click events for rutime generated controls

Please support our C# advertiser: Intel Parallel Studio Home
Reply

Join Date: Aug 2009
Posts: 316
Reputation: Ryshad has a spectacular aura about Ryshad has a spectacular aura about 
Solved Threads: 57
Ryshad's Avatar
Ryshad Ryshad is online now Online
Posting Whiz
 
1
  #11
19 Days Ago
Originally Posted by Ryshad View Post
What values do you need to pass? Unless you right a custom event handler, the click event has a defined argument list.
You can check which button was clicked inside the event handler by converting Sender back to a button:

  1. Button btnClicked = (Button)sender;
  2. if(btnClicked.Name=="Button1")
  3. //do something

Alternaively, if each button has different behaviour then give each one a different handler:

  1. private void Form1_Load(object sender, EventArgs e)
  2. {
  3. Button b1 = new Button();
  4. b1.Click += new EventHandler(b1_Click);
  5. Button b2 = new Button();
  6. b2.Click += new EventHandler(b2_Click);
  7. }
  8. void b1_Click(object sender, EventArgs e)
  9. {
  10. // put your code
  11. }
  12. void b2_Click(object sender, EventArgs e)
  13. {
  14. // put your code
  15. }
Does this look familiar to anyone else?...sure i've seen that code somewhere before
Please don't take for granted the work that solvers do for you. Take the time to fully understand the code they give you so that you might adapt it to future problems.

"Learning is more than absorbing facts, it is acquiring understanding.” - William Arthur Ward
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 3,187
Reputation: sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of 
Solved Threads: 571
Sponsor
sknake's Avatar
sknake sknake is offline Offline
.NET Enthusiast
 
0
  #12
18 Days Ago
bk_bhupendra,

Please stop using [quote][/quote] quotes for all of your posts. That is intended for quoting other people when you want to reply to their post. Just post your responses in the normal whitespace of the reply box. Use [code][/code] when posting code.
Scott Knake
Custom Software Development
Apex Software, Inc.
Reply With Quote Quick reply to this message  
Reply

Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC