答案 0 :(得分:0)
更好的方法是循环访问组框控件并检查是否选中了复选框,如果是,则将其附加到某个字符串。在完成所有检查后,使用messagebox.Simple原样显示字符串。为解决方案提供更多信息,请通过以下代码
循环控制
Dim strfinal As String
For Each gb As Control In Me.Controls
If gb.GetType() Is GetType(GroupBox) Then
Dim str As String
str = gb.Text
For Each c As CheckBox In gb.Controls
If c.Checked = True Then
str = str + vbNewLine + c.Text
End If
Next
If str <> "" Then
strfinal = strfinal + vbNewLine + str
End If
End If
Next
并在消息框中显示
If strfinal <> "" Then
MessageBox.Show(strfinal, "somecaption", MessageBoxButtons.OK)
End If
希望这会有所帮助。
答案 1 :(得分:0)
此代码将完全按照上面的图片2给出结果:
Dim Toppings As String = "Toppings:" & VbCrlf
Dim TSize As String = "Size:"
Dim CrustType As String = "Crust Type:"
当您按下Button1时,当包含浇头的groubBox的名称为'ToppingsGroupBox'时,其他groupBox的名称相同:
For Each CB As CheckBox In ToppingsGroupBox.Controls
If CB.Checked Then
Toppings &= "-" & CB.Text & VbCrlf
End If
End Each
For Each RB As RadioButton In SizesGroupBox.Controls
If RB.Checked Then
TSize &= RB.Text
End If
End Each
For Each RB As RadioButton In CurstTypeGroupBox.Controls
If RB.Checked Then
CurstType &= RB.Text
End If
End Each
If DineInRadioBox.Checked Then
MsgBox(TSize & VbCrlf & CurstType & Toppings & "*Dine In")
Else
MsgBox(TSize & VbCrlf & CurstType & Toppings & "*Take Out")
End If
希望能帮到你:)