The RadioButton in the Winform

QQ contact meBaidu BLOG

The new event code as follows:

Copy the code
// RadioButton新事件
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 ;
}
}
Copy the code

 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:

 

Copy the code
public StartPage()
{
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);
}
Copy the code

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

Guess you like

Origin blog.csdn.net/weixin_34252686/article/details/93439969