2个回答
展开全部
建议使用控件数组;方法
1,添加一个复选框.
2,窗体上选中该复选框,单击[复制],在窗体上任意位置单击,单击[粘贴],回答“是”,继续粘贴2个。
这4个复选框名分别为:Check1(0)、Check1(1)、Check1(2)、Check1(3)。
代码如下:
Private Sub Check1_Click(Index As Integer)
Dim i As Integer
Label1.Caption = ""
For i = 0 To 3
If Check1(i).Value = 1 Then
Label1.Caption = Label1.Caption & " " & Check1(i).Caption
End If
Next i
End Sub
1,添加一个复选框.
2,窗体上选中该复选框,单击[复制],在窗体上任意位置单击,单击[粘贴],回答“是”,继续粘贴2个。
这4个复选框名分别为:Check1(0)、Check1(1)、Check1(2)、Check1(3)。
代码如下:
Private Sub Check1_Click(Index As Integer)
Dim i As Integer
Label1.Caption = ""
For i = 0 To 3
If Check1(i).Value = 1 Then
Label1.Caption = Label1.Caption & " " & Check1(i).Caption
End If
Next i
End Sub
追问
....初学者,没学到。。。希望简单点,比如dim几个变量,通过选择checkbox赋值,改变label的caption,万分感谢!
展开全部
Private Sub UnCheckAll()
Dim x As Control
For Each x In Me.Controls
If TypeOf x Is CheckBox Then x.Value = vbUnchecked: Label1.Caption = ""
Next
End Sub
Private Sub Check1_Click()
If Check1.Value = vbUnchecked Then UnCheckAll Else Label1 = Check1.Caption
End Sub
Private Sub Check2_Click()
If Check2.Value = vbUnchecked Then UnCheckAll Else Label1 = Check2.Caption
End Sub
Private Sub Check3_Click()
If Check3.Value = vbUnchecked Then UnCheckAll Else Label1 = Check3.Caption
End Sub
Private Sub Check4_Click()
If Check4.Value = vbUnchecked Then UnCheckAll Else Label1 = Check4.Caption
End Sub
Dim x As Control
For Each x In Me.Controls
If TypeOf x Is CheckBox Then x.Value = vbUnchecked: Label1.Caption = ""
Next
End Sub
Private Sub Check1_Click()
If Check1.Value = vbUnchecked Then UnCheckAll Else Label1 = Check1.Caption
End Sub
Private Sub Check2_Click()
If Check2.Value = vbUnchecked Then UnCheckAll Else Label1 = Check2.Caption
End Sub
Private Sub Check3_Click()
If Check3.Value = vbUnchecked Then UnCheckAll Else Label1 = Check3.Caption
End Sub
Private Sub Check4_Click()
If Check4.Value = vbUnchecked Then UnCheckAll Else Label1 = Check4.Caption
End Sub
追问
取消时,相应的caption消失!不哈意思,我表述有错!希望能继续帮忙!谢谢!
追答
把上面的Label1.Caption = ""改为
x.Caption = ""
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询