how to display on a messagebox, which radio button was selected
我有2个用于性别的单选按钮。一位男性(命名为
1 | MessageBox.Show(radMale ="Male"); |
我知道这行不通,有人知道哪个代码吗?
我尝试执行以下代码来解决您的问题。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | public partial class Form1: Form { public Form1() { InitializeComponent(); this.Load += new EventHandler(Form1_Load); radioButton1.CheckedChanged += new EventHandler(radioButton_CheckedChanged); radioButton2.CheckedChanged += new EventHandler(radioButton_CheckedChanged); } void radioButton_CheckedChanged(object sender, EventArgs e) { RadioButton rb = (RadioButton)sender; if(rb.Checked) MessageBox.Show(rb.Text); //Shows whatever Text your radiobutton has } void Form1_Load(object sender, EventArgs e) { } } |
在WinForms中,使用此命令:
1 |