【问题标题】:How to get the object name of a changed checkbox-item?如何获取已更改复选框项的对象名称?
【发布时间】:2013-07-17 20:36:41
【问题描述】:

我想得到一个复选框的.(name)-Proterty,它已经被改变了?
我只需要在 Messagebox 上显示一个小示例。

小片段:

namespace Checkboxes
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();

            this.chkCar.Name = "chkCar";
            this.chkCar.Text = "chkCar";
            this.chkHouse.Name = "chkHouse";
            this.chkHouse.Text = "chkHouse";
            this.chkSea.Name = "chkSea";
            this.chkSea.Text = "chkSea";
            this.chkWood.Name = "chkWood";
            this.chkWood.Text = "chkWood";
            this.chkCar.CheckedChanged += new System.EventHandler(this.GeneralCheckboxItem_CheckedChanged);
            this.chkHouse.CheckedChanged += new System.EventHandler(this.GeneralCheckboxItem_CheckedChanged);
            this.chkSea.CheckedChanged += new System.EventHandler(this.GeneralCheckboxItem_CheckedChanged);
            this.chkWood.CheckedChanged += new System.EventHandler(this.GeneralCheckboxItem_CheckedChanged);
        }

        private void GeneralCheckboxItem_CheckedChanged(object sender, EventArgs e)
        {
            MessageBox.Show(/*Name of changed checkbox*/);
        }
    }
}

【问题讨论】:

    标签: c# properties oncheckedchanged


    【解决方案1】:

    我想这就是你要找的东西:

    CheckBox c = sender as CheckBox;
    MessageBox.Show(c.Name);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-16
      • 1970-01-01
      • 2015-07-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多