我打算动态生成控件后,再动态删除它。这该怎么办呢?
我把程序贴在下面:
Option Explicit
Private WithEvents NewButton As CommandButton
Private WithEvents Label1 As Label
Private WithEvents Label2 As Label
Private WithEvents Text1 As TextBox
Private WithEvents Combo1 As ComboBox
Private Sub optHalf_Click()
If Label1 Is Nothing = False Then
Set Label1 = Nothing
End If
If Label2 Is Nothing Then
Set Label2 = Controls.Add("VB.Label", "labNew1", Me)
Label2.Move 3440, 2040, 855, 375
Label2.Caption = "半年:"
Label2.Visible = True
End If
If Combo1 Is Nothing Then
Set Combo1 = Controls.Add("VB.ComboBox", "CmbNew", Me)
Combo1.Move 4000, 1920, 1095
Combo1.AddItem "上半年", 0
Combo1.AddItem "下半年", 1
Combo1.Visible = True
End If
End SubPrivate Sub optSeason_Click()
If Label2 Is Nothing = False Then
'Label1.Visible = False
Set Label2 = Nothing
' Label2.Visible = False
End If
If Combo1 Is Nothing = False Then
Set Combo1 = Nothing
'Combo1.Visible = False
End If
If Label2 Is Nothing Then
Set Label2 = Controls.Add("VB.Label", "labNew2", Me)
Label2.Move 3440, 2040, 855, 375
Label2.Caption = "月:"
Label2.Visible = True
End If
If Combo1 Is Nothing Then
Set Combo1 = Controls.Add("VB.ComboBox", "CmbNew1", Me)
Combo1.Move 4000, 1920, 1095
Combo1.AddItem "1", 0
Combo1.AddItem "2", 1
Combo1.Visible = True
End If
End Sub
我把程序贴在下面:
Option Explicit
Private WithEvents NewButton As CommandButton
Private WithEvents Label1 As Label
Private WithEvents Label2 As Label
Private WithEvents Text1 As TextBox
Private WithEvents Combo1 As ComboBox
Private Sub optHalf_Click()
If Label1 Is Nothing = False Then
Set Label1 = Nothing
End If
If Label2 Is Nothing Then
Set Label2 = Controls.Add("VB.Label", "labNew1", Me)
Label2.Move 3440, 2040, 855, 375
Label2.Caption = "半年:"
Label2.Visible = True
End If
If Combo1 Is Nothing Then
Set Combo1 = Controls.Add("VB.ComboBox", "CmbNew", Me)
Combo1.Move 4000, 1920, 1095
Combo1.AddItem "上半年", 0
Combo1.AddItem "下半年", 1
Combo1.Visible = True
End If
End SubPrivate Sub optSeason_Click()
If Label2 Is Nothing = False Then
'Label1.Visible = False
Set Label2 = Nothing
' Label2.Visible = False
End If
If Combo1 Is Nothing = False Then
Set Combo1 = Nothing
'Combo1.Visible = False
End If
If Label2 Is Nothing Then
Set Label2 = Controls.Add("VB.Label", "labNew2", Me)
Label2.Move 3440, 2040, 855, 375
Label2.Caption = "月:"
Label2.Visible = True
End If
If Combo1 Is Nothing Then
Set Combo1 = Controls.Add("VB.ComboBox", "CmbNew1", Me)
Combo1.Move 4000, 1920, 1095
Combo1.AddItem "1", 0
Combo1.AddItem "2", 1
Combo1.Visible = True
End If
End Sub
例如
Controls.Remove Combo1