vb 中combox控件的使用
我在combox控件中用additem增加了1-3这五个数字,当前窗体上有3个COMMAND,我想实现这样的效果,我选中combox中的1,按扭1可见并且可用,其它不可用...
我在combox控件中用additem增加了1-3这五个数字,当前窗体上有3个COMMAND,我想实现这样的效果,我选中combox中的1,按扭1可见并且可用,其它不可用,隐藏,先中2就是按扭2可用可见,其它不可见不可用。
展开
展开全部
'添加窗体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
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
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
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询