vb.net中读取多个groupbox中的radiobutton的值
我想把多个groupbox中分别选中的多个radiobutton的值相加,怎么获取这些radiobutton的值呢???
求代码,我是新手,groupbox的用法不熟 展开
每个radiobutton取个名字,或者建立一个radiobutton()的数组,把所有处于选中的radiobutton的值相加
groupbox只是一个分组的容器同一groupbox内的radioButton只能有一个Checked 属性为True
radioButton1-5 radioButton是5个radioButton控件
Public Partial Class MainForm
Dim arrRB As RadioButton()
Public Sub New()
' The Me.InitializeComponent call is required for Windows Forms designer support.
Me.InitializeComponent()
'
' TODO : Add constructor code after InitializeComponents
'
arrRB={radioButton1,radioButton2,radioButton3,radioButton4,radioButton5}
End Sub
Sub MainFormClick(sender As Object, e As EventArgs)
Dim sum As Integer
sum=0
For Each item As RadioButton In arrRB
If item.Checked Then'判断RadioButton是否被选择
sum+=Convert.ToInt32( item.Text)'字符串转换为Integer,并累加
End If
Next
MessageBox.Show(sum.ToString())'输出最后结果
End Sub
Sub MainFormLoad(sender As Object, e As EventArgs)
End Sub
End Class