我想获取.(name)
- 复选框的属性,该属性已更改?
我只需要在Messagebox上显示一个小例子。
Little Snippet:
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*/);
}
}
}
答案 0 :(得分:4)
我认为这就是你要找的东西:
CheckBox c = sender as CheckBox;
MessageBox.Show(c.Name);