When multiple RadioButton in a container inside the same time, most of the operations are to get the value of one of this time we do not need to write a CheckedChange event for each RadioButton, I will write a lot of code, too tired. This time we will be staying entrust to add a new event, instead of all RadioButton CheckedChange event with a new event. Asked me to realize is this: When you select a RadioButton any time Label17 I chose to become Text value of the RadioButton
The new event code as follows:
public void radioBtn_CheckedChange( object sender, EventArgs e)
{
if ( ! ((RadioButton)sender).Checked)
{
return ;
}
string rechargeMoney = string .Empty;
switch (((RadioButton)sender).Text.ToString())
{
case " 10 " :
rechargeMoney = " 10 " ;
this .lbl_money_tip.Text = rechargeMoney;
break ;
case " 20 " :
rechargeMoney = " 20 " ;
this .lbl_money_tip.Text = rechargeMoney;
break ;
case " 30 " :
rechargeMoney = " 30 " ;
this .lbl_money_tip.Text = rechargeMoney;
break ;
case " 40 " :
rechargeMoney = " 40 " ;
this .lbl_money_tip.Text = rechargeMoney;
break ;
case " 50 " :
rechargeMoney = " 50 " ;
this .lbl_money_tip.Text = rechargeMoney;
break ;
case " 100 " :
rechargeMoney = " 100 " ;
this .lbl_money_tip.Text = rechargeMoney;
break ;
default :
break ;
}
}
How to use this incident? There are two ways
1, and right-click to select each RadioButton in VS2008 - the "Properties" to find CheckedChange events in the property, the event is assigned a new written. As shown below:
2, add the following code to initialize when the form:
{
InitializeComponent();
this .radio_Money_10.CheckedChanged += new EventHandler( this .radioBtn_CheckedChange);
this .radio_Money_20.CheckedChanged += new EventHandler( this .radioBtn_CheckedChange);
this .radio_Money_30.CheckedChanged += new EventHandler( this .radioBtn_CheckedChange);
this .radio_Money_40.CheckedChanged += new EventHandler( this .radioBtn_CheckedChange);
this .radio_Money_50.CheckedChanged += new EventHandler( this .radioBtn_CheckedChange);
this .radio_Money_100.CheckedChanged += new EventHandler( this .radioBtn_CheckedChange);
}
This simple approach to this is complete, so I wrote a lot less junk codes; can learn by analogy. For example, check box is selected, spread out a value, and so on. This has also allowed me to have a clearer understanding commission.
Reproduced in: https: //www.cnblogs.com/baishiying/archive/2012/10/15/2724053.html