我想创建一个文本框实例,代码如下,
可是运行的时候却提示“用户定义类型未定义”
请大侠指点迷津,谢谢
Private Sub Command1_Click()
Dim objTxt As Object
Set objTxt = New Text1
End Sub
可是运行的时候却提示“用户定义类型未定义”
请大侠指点迷津,谢谢
Private Sub Command1_Click()
Dim objTxt As Object
Set objTxt = New Text1
End Sub
Option Explicit
Private WithEvents btnObj As TextBoxPrivate Sub btnObj_Click()
MsgBox "This is a dynamically added button."
End SubPrivate Sub Form_Load()
Set btnObj = Controls.Add("VB.TextBox", "btnObj")
With btnObj
.Visible = True
.Width = 2000
.Top = 1000
.Left = 1000
End With
End Sub
Select Case Index
Case 0
MsgBox "这是手工创建的按钮!" '这个有效
Case Else
MsgBox "这是程序创建的按钮!" & Index '但这些就没用了
End SelectEnd SubPrivate Sub Command1_Click()
Dim cmd1(11) As CommandButton '这个没办法创建成 Dim WithEvents cmd1(11) as CommandButton
For i = 1 To 11 Set cmd1(i) = Controls.Add("VB.CommandButton", "CmdNew" & i, Form1)
cmd1(i).Left = 1000 * i
cmd1(i).Visible = True
Next i
End SubPrivate Sub Command2_Click()
Set cmd2 = Controls.Add("VB.CommandButton", "cmd3")
cmd2.Left = 1000
cmd2.Visible = True
End Sub
Private Sub cmd2_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
MsgBox "这是程序创建的按钮!" '这个事件有用
End Sub
这是基本用法
Private WithEvents txtNew As TextBoxPrivate Sub Form_Load()
Set txtNew = Controls.Add("VB.TextBox", "txtNew")
With txtNew
.Visible = True
.Width = 2000
.Top = 1000
.Left = 1000
.Text = "New TextBox."
End With
End Sub