📄 add_control_runtime.frm
字号:
VERSION 5.00
Begin VB.Form Form1
AutoRedraw = -1 'True
Caption = "Run Time Demo"
ClientHeight = 4620
ClientLeft = 60
ClientTop = 345
ClientWidth = 6405
LinkTopic = "Form1"
ScaleHeight = 4620
ScaleWidth = 6405
StartUpPosition = 3 'Windows Default
WindowState = 2 'Maximized
Begin VB.CommandButton Command5
Caption = "Remove &Array"
BeginProperty Font
Name = "MS Sans Serif"
Size = 12
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 495
Left = 5400
TabIndex = 5
Top = 4440
Width = 2055
End
Begin VB.CommandButton Command4
Caption = "&Create Label "
BeginProperty Font
Name = "MS Sans Serif"
Size = 12
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 435
Left = 5400
TabIndex = 3
Top = 3840
Width = 2055
End
Begin VB.CommandButton Command3
Caption = "E&xit"
BeginProperty Font
Name = "MS Sans Serif"
Size = 12
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 495
Left = 5520
TabIndex = 2
Top = 1920
Width = 1695
End
Begin VB.CommandButton Command2
Caption = "&Remove Control"
BeginProperty Font
Name = "MS Sans Serif"
Size = 12
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 495
Left = 5040
TabIndex = 1
Top = 1080
Width = 3135
End
Begin VB.CommandButton Command1
Caption = "&Add Control Dynamically"
BeginProperty Font
Name = "MS Sans Serif"
Size = 12
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 495
Left = 5040
TabIndex = 0
Top = 480
Width = 3135
End
Begin VB.Label Label1
AutoSize = -1 'True
Caption = "Hello"
BeginProperty Font
Name = "MS Sans Serif"
Size = 12
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 300
Index = 0
Left = 1440
TabIndex = 4
Top = 4200
Width = 540
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim t As Long
Dim l As Long
Dim i As Integer
Private Sub Command1_Click()
On Error GoTo sa
Dim ctl As Control
Dim ctlType As String
Dim ctlName As String
i = i + 1
'ctlType = "VB." & InputBox("Enter the Type of Control")
'ctlName = InputBox("Enter the Name of Control")
Set ctl = Form1.Controls.Add("VB.TextBox", "Text" & i, Form1)
'Set ctl = Form1.Controls.Add(ctlType, ctlName, Form1)
With ctl
.Visible = True
.Top = 800 * i
.Left = 400
.Width = 4000
.Height = 400
.Font.Size = 12
.Text = "Developed By Sachin Dhillan"
.Appearance = 0
End With
Exit Sub
sa:
MsgBox Err.Description, vbInformation, "Error"
End Sub
Private Sub Command2_Click()
On Error GoTo er
If i = 0 Then Exit Sub
Form1.Controls.Remove "Text" & i
i = i - 1
Exit Sub
er:
MsgBox Err.Description, , "Warning"
End Sub
Private Sub Command3_Click()
'If UCase(un.Text) = ("SACHIN") Then
End
'Else
'MsgBox "Sorry User" & vbCrLf & "Enter Right Name", vbCritical, "Warning"
'un.SetFocus
'un.SelStart = 0
'un.SelLength = Len(un.Text)
'End If
End Sub
Private Sub Command4_Click()
t = t + 500
l = 500
On Error GoTo er
Load Label1(Label1.UBound + 1)
Debug.Print t
Label1(Label1.UBound).Top = t
Label1(Label1.UBound).Left = l
Label1(Label1.UBound).Caption = "Dynamically genetrated Label By array"
Label1(Label1.UBound).BackColor = vbBlue
Label1(Label1.UBound).ForeColor = vbRed
Label1(Label1.UBound).Font.Size = 12
Label1(Label1.UBound).AutoSize = True
Label1(Label1.UBound).Visible = True
Exit Sub
er:
MsgBox Err.Description, , "Warning"
End Sub
Private Sub Command5_Click()
On Error GoTo er
If t = 500 Then Exit Sub
Unload Label1(Label1.UBound)
t = t - 500
Exit Sub
er:
MsgBox Err.Description, , "Warning"
End Sub
Private Sub Form_Load()
t = 500
i = 0
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
If UnloadMode <> vbFormCode Then
MsgBox "Sorry User" & vbCrLf & "Use the Exit button to close the Form", vbCritical, "Warning"
Cancel = True
End If
End Sub
Private Sub un_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
Command2_Click
End If
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -