这个办法很多种,radiobutton本身没有Value属性,可以使用其Tag属性来表示其值,上面的程序加上List.Item(i).Tag="你要传递的值";也可以在动态增加该控件中使用一个String数组来保存其对应的值
程序代码:
Public Class Form1
'以下代码需要在窗体中画出一个按钮Button1
Dim SelectRadio As New RadioButton
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim List As New ArrayList
For i As Integer = 0 To 4
Dim s As Double = 0
Dim ck As New RadioButton
Me.Controls.Add(ck)
List.Add(ck)
List.Item(i).name = "RadioButton" & i.ToString
List.Item(i).text = List.Item(i).name
List.Item(i).Tag = Rnd(10).ToString'我这里用了一个随机数,表示这一题目答案吧
List.Item(i).width = 250
If i = 0 Then
List.Item(i).top = 3
Else
List.Item(i).top = List.Item(i - 1).top + List.Item(i - 1).height + 3
End If
List.Item(i).left = 5
List.Item(i).tabindex = i
List.Item(i).Visible = True
AddHandler ck.Click, AddressOf RadioButton1_Click
Next
End Sub
Private Sub RadioButton1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
SelectRadio = sender
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
MsgBox(SelectRadio.Name & " 这一题的答案是" & SelectRadio.Tag)
End Sub
End Class
[
本帖最后由 不说也罢 于 2011-6-5 17:17 编辑 ]
===================================================
讨厌C#的行尾的小尾巴;和一对大括号{ }
===================================================