下面的代码可以自动创建控件,但不能是数组控件
Option Explicit
Dim oControl As Object '窗体级变量
Private Sub Command1_Click()
Set oControl = Controls.Add("VB.TextBox", "MyButton")
oControl.Move 10, 10, 2000, 380
oControl.Visible = True '使控件可见
End Sub
...全文
439打赏收藏
如何动态创建数组控件,高手请进
下面的代码可以自动创建控件,但不能是数组控件 Option Explicit Dim oControl As Object '窗体级变量 Private Sub Command1_Click() Set oControl = Controls.Add("VB.TextBox", "MyButton") oControl.Move 10, 10, 2000, 380 oControl.Visible = True '使控件可见 End Sub
'add a commandbutton whose name is "newbutton"and index is 0,visiable is false
Option Explicit
Private Sub Form_Click()
addcmdline
End Sub
Sub addcmdline()
Me.WindowState = 2
On Error Resume Next
Dim i As Long
For i = 0 To 99
Load newbutton(i)
newbutton(i).Left = (i Mod 10) * 1000 + 1050
newbutton(i).Top = (i \ 10) * 500 + 550
newbutton(i).Caption = "cmd" & i
newbutton(i).Width = 900
newbutton(i).Height = 400
newbutton(i).Visible = True
Next
Me.ForeColor = vbRed
Me.DrawWidth = 3
For i = 0 To 10
Me.Line (1000, 500 + i * 500)-(11000, 500 + 500 * i)
Me.Line (1000 + i * 1000, 500)-(1000 + 1000 * i, 5500)
Next
End Sub
Private Sub newbutton_Click(Index As Integer)
MsgBox " You have clicked " & newbutton(Index).Caption, 64
End Sub