Dim
WithEvents cmdMyCommand
As
VB.CommandButton
Option Explicit
Dim WithEvents ctlDynamic As VBControlExtender
Dim WithEvents ctlText As VB.TextBox
Dim WithEvents ctlCommand As VB.CommandButton
Dim WithEvents ctlCommandDel As VB.CommandButton
Private Sub ctlCommandDel_Click()
Dim i As Integer
Licenses.Remove " MSComctlLib.TreeCtrl "
If MsgBox ( " 是否删除所有控件 " , vbYesNo) = vbYes Then
For i = 1 To Form1.Controls.Count
Controls.Remove 0
Next i
End If
End Sub
Private Sub ctlCommand_Click()
ctlText.Text = " 你点击的是控制按钮 "
End Sub
Private Sub ctlDynamic_ObjectEvent(Info As EventInfo)
If Info.Name = " Click " Then
ctlText.Text = " 你点击的条目是 " & _
ctlDynamic.object.selecteditem.Text
End If
End Sub
Private Sub Form_Load()
Dim i As Integer
Licenses.Add " MSComctlLib.TreeCtrl "
Set ctlDynamic = Controls.Add( " MSComctlLib.TreeCtrl " , _
" myctl " , Form1)
ctlDynamic.Move 1 , 1 , 2500 , 3500
For i = 1 To 10
ctlDynamic.object.nodes.Add Key: = " Test " & Str(i), _
Text: = " Test " & Str(i)
ctlDynamic.object.nodes.Add Relative: = " Test " & Str(i), _
Relationship: = 4 , Text: = " TestChild " & Str(i)
Next i
ctlDynamic.Visible = True
Set ctlText = Controls.Add( " VB.TextBox " , " ctlText1 " , Form1)
ctlText.Move (ctlDynamic.Left + ctlDynamic.Width + 50 ), _
1 , 2500 , 100
ctlText.BackColor = vbBlue
ctlText.ForeColor = vbWhite
ctlText.Visible = True
Set ctlCommand = Controls.Add( " VB.CommandButton " , _
" ctlCommand1 " , Form1)
ctlCommand.Move (ctlDynamic.Left + ctlDynamic.Width + 50 ), _
ctlText.Height + 50 , 1500 , 500
ctlCommand.Caption = " 点击 "
ctlCommand.Visible = True
Set ctlCommandDel = Controls.Add( " VB.CommandButton " , _
" ctlCommand2 " , Form1)
ctlCommandDel.Move (ctlDynamic.Left + ctlDynamic.Width + 50 ), _
ctlText.Height + 650 , 1500 , 500
ctlCommandDel.Caption = " 删除所有控件 "
ctlCommandDel.Visible = True
End Sub
Option Explicit
Dim WithEvents ctlDynamic As VBControlExtender
Dim WithEvents ctlText As VB.TextBox
Dim WithEvents ctlCommand As VB.CommandButton
Dim WithEvents ctlCommandDel As VB.CommandButton
Private Sub ctlCommandDel_Click()
Dim i As Integer
Licenses.Remove " MSComctlLib.TreeCtrl "
If MsgBox ( " 是否删除所有控件 " , vbYesNo) = vbYes Then
For i = 1 To Form1.Controls.Count
Controls.Remove 0
Next i
End If
End Sub
Private Sub ctlCommand_Click()
ctlText.Text = " 你点击的是控制按钮 "
End Sub
Private Sub ctlDynamic_ObjectEvent(Info As EventInfo)
If Info.Name = " Click " Then
ctlText.Text = " 你点击的条目是 " & _
ctlDynamic.object.selecteditem.Text
End If
End Sub
Private Sub Form_Load()
Dim i As Integer
Licenses.Add " MSComctlLib.TreeCtrl "
Set ctlDynamic = Controls.Add( " MSComctlLib.TreeCtrl " , _
" myctl " , Form1)
ctlDynamic.Move 1 , 1 , 2500 , 3500
For i = 1 To 10
ctlDynamic.object.nodes.Add Key: = " Test " & Str(i), _
Text: = " Test " & Str(i)
ctlDynamic.object.nodes.Add Relative: = " Test " & Str(i), _
Relationship: = 4 , Text: = " TestChild " & Str(i)
Next i
ctlDynamic.Visible = True
Set ctlText = Controls.Add( " VB.TextBox " , " ctlText1 " , Form1)
ctlText.Move (ctlDynamic.Left + ctlDynamic.Width + 50 ), _
1 , 2500 , 100
ctlText.BackColor = vbBlue
ctlText.ForeColor = vbWhite
ctlText.Visible = True
Set ctlCommand = Controls.Add( " VB.CommandButton " , _
" ctlCommand1 " , Form1)
ctlCommand.Move (ctlDynamic.Left + ctlDynamic.Width + 50 ), _
ctlText.Height + 50 , 1500 , 500
ctlCommand.Caption = " 点击 "
ctlCommand.Visible = True
Set ctlCommandDel = Controls.Add( " VB.CommandButton " , _
" ctlCommand2 " , Form1)
ctlCommandDel.Move (ctlDynamic.Left + ctlDynamic.Width + 50 ), _
ctlText.Height + 650 , 1500 , 500
ctlCommandDel.Caption = " 删除所有控件 "
ctlCommandDel.Visible = True
End Sub