Question

I want to get the .(name)-Proterty of a checkbox, which has been changed?
I need just a little example shown on a Messagebox.

Form1

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*/);
        }
    }
}
Was it helpful?

Solution

I think this is what you're looking for:

CheckBox c = sender as CheckBox;
MessageBox.Show(c.Name);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top