المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Retrieve the control's name



C# Programming
11-29-2009, 08:32 AM
Hello!

I'm working on an application wich will alow the user to add and remove controls. I want to apply different rules to textbox and this rules will be different for every textbox. For example i want to check wich control has been clicked by using a click event. Because i don't know how many textboxes will the user create i've decided to go along with the code below:


private void Form1_Load(object sender, EventArgs e)
{
foreach (Control ctrl in Controls)
{
ctrl.Click += new EventHandler(ctrl_Click);
}
}

void ctrl_Click(object sender, EventArgs e)
{

}


Is there anyway that i can get the name of the control that has been clicked? The sender.Tostring() only returns the type and the text of the control.


Thanks! http://www.barakasoft.com/script/Forums/Images/smiley_wink.gif