zoukankan      html  css  js  c++  java
  • Winform的RadioButton的使用

    QQ联系我百度BLOG

    新事件代码如下:

    复制代码
    //RadioButton新事件
    publicvoid 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;
    }
    }
    复制代码

     如何使用这个事件呢?有两种方法

    1、在VS2008中依次选中每一个RadioButton右击--“属性”在属性中找到CheckedChange事件,为其指定为新写的事件。如下图:

    2、在初始化窗体的时候添加如下代码:

    复制代码
    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);
    }
    复制代码

    到此这个简单的方法就完成了,让我少写了不少的垃圾代码;可以举一反三。比如复选框被选中,传出去一个值等等。这也让我对委托有了更清晰了理解。

     
  • 相关阅读:
    v-date
    文字在图片上
    v-生命周期
    彭博接口分类
    如何指定vim 的查找是从上往下还是从下往上[z]
    查看linux版本
    git web找不到new project解决方法
    比特币运行原理[z]
    [Z]haproxy+keepalived高可用群集
    blockchain good article
  • 原文地址:https://www.cnblogs.com/baishiying/p/2724053.html
Copyright © 2011-2022 走看看