471,348 Members | 1,358 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,348 software developers and data experts.

Multiple Controls

Using Windows Form C# in .NET 3.5

I have 12 controls on a form. When one of them is clicked I want a common
event handler to do the processing and substitute a single property on the
form. There is a different value for the property in each control.

Is there a standard way to determine which control was clicked and to make a
substitution like this one? Can you point me to an example?

.... Thom
__________________________________________________ _
Thom Little - www.tlanet.net - Thom Little Associates, Ltd.
Jun 27 '08 #1
3 881
You can find which button was called by casting "sender" to Button.
For the property, well - I guess Tag would be a suitable place to
store extra info - i.e. set the Tag of each button to the required
value:
void SharedHandler(object sender, EventArgs args) {
Button btn = sender as Button;
if(btn == null) return; // wtf?
this.SomeProperty = (string)btn.Tag; // subst with desired type of
SomeProperty
}

Jun 27 '08 #2
(oh, replace "Button" with "Control" if you meant any control; I had
Button on the brain...)
Jun 27 '08 #3
I was not seeing it ... it is now working thanks to your message.

Thanks for the help.

.... Thom
__________________________________________________ _
Thom Little - www.tlanet.net - Thom Little Associates, Ltd.
Jun 27 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by Gaetan | last post: by
3 posts views Thread by Shikari Shambu | last post: by
3 posts views Thread by Nathan Sokalski | last post: by
11 posts views Thread by Ranginald | last post: by
3 posts views Thread by =?Utf-8?B?a3dvbmd0aw==?= | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.