Welcome to Dream.In.Code
Getting C# Help is Easy!

Join 136,163 C# Programmers for FREE! Get instant access to thousands of C# experts, tutorials, code snippets, and more! There are 1,883 people online right now. Registration is fast and FREE... Join Now!




Detecting events of child controls in parent

 
Reply to this topicStart new topic

Detecting events of child controls in parent

cygnusX
29 Dec, 2007 - 04:10 AM
Post #1

D.I.C Head
**

Joined: 19 May, 2007
Posts: 159



Thanked: 2 times
My Contributions
Can parent control detect child controls events?I mean for example i have panel with many buttons in it and instead of adding click event handler to every button can i handle their click events in different manner?I just want to know which button exatcly is pressed.Can i do it without adding event handlers for every button?
User is offlineProfile CardPM
+Quote Post

baavgai
RE: Detecting Events Of Child Controls In Parent
29 Dec, 2007 - 04:49 AM
Post #2

Dreaming Coder
Group Icon

Joined: 16 Oct, 2007
Posts: 2,019



Thanked: 105 times
Dream Kudos: 475
Expert In: C, C++, Java, C#, ASP.NET, PHP, Perl, Python, Oracle, SQL Server, MySql, HTML, JavaScript, Lua

My Contributions
Yes and yes. A button control has a click event. The ide usually handles the details, but you can certainly do them on your own. Here's an example:

CODE

public form1() {

   InitializeComponent();
   this.button1.Click += new System.EventHandler(this.myClickHandler);

   this.button2.Click += new System.EventHandler(this.myClickHandler);
   this.button3.Click += new System.EventHandler(this.myClickHandler);
}


private void myClickHandler(object sender, System.EventArgs e) {
   Button button = (Button)sender;
   if (button==this.button1) {
   } else if (button==this.button2) {
...


Hope this helps.

User is offlineProfile CardPM
+Quote Post

cygnusX
RE: Detecting Events Of Child Controls In Parent
29 Dec, 2007 - 08:22 AM
Post #3

D.I.C Head
**

Joined: 19 May, 2007
Posts: 159



Thanked: 2 times
My Contributions
Thanks
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/1/08 11:54PM

Live C# Help!

C# Tutorials

Reference Sheets

C# Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month