1

我想获得.(name)已更改的复选框的-Proterty?
我只需要在 Messagebox 上显示一个小例子。

表格1

小片段:

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*/);
        }
    }
}
4

1 回答 1

4

我想这就是你要找的:

CheckBox c = sender as CheckBox;
MessageBox.Show(c.Name);
于 2013-07-17T20:39:08.303 回答