'添加窗体Form1,按钮Command1,Command2,Command3,组合框Combo1,然后添加如下代码:
Private Sub Form_Load()
Combo1.AddItem "1"
Combo1.AddItem "2"
Combo1.AddItem "3"
Command1.Visible = False
Command2.Visible = False
Command3.Visible = False
End Sub
Private Sub Combo1_Click()
Command1.Visible = False
Command2.Visible = False
Command3.Visible = False
If Combo1.Text = "1" Then
Call setButton(Command1)
ElseIf Combo1.Text = "2" Then
Call setButton(Command2)
Else
Call setButton(Command3)
End If
End Sub
Private Sub setButton(cmd1 As CommandButton)
cmd1.Visible = True
cmd1.Enabled = True
End Sub
Sub ShowButton(ButtonNum As Long) '自定义过程
Dim i As Control
For Each i In Me.Controls
If TypeOf i Is CommandButton Then i.Visible = False
'把每一个Commandbutton设为不可见
Next
If ButtonNum Then Me.Controls("Command" & ButtonNum).Visible = True
'如果传入参数不为零,则将参数所指的CommandButton设为可见
End Sub
Private Sub Combo1_Click()
ShowButton Combo1.Text 'Call自定义过程
End Sub
Private Sub Form_Load()
Combo1.Text = "请选择"
Combo1.AddItem 1 '初始数据
Combo1.AddItem 2
Combo1.AddItem 3
ShowButton 0 '使所有CommandButton不可见
End Sub