Button activate other button

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

Join Date: Feb 2008
Posts: 517
Reputation: Jennifer84 is an unknown quantity at this point 
Solved Threads: 1
Jennifer84 Jennifer84 is offline Offline
Posting Pro

Button activate other button

 
0
  #1
May 6th, 2008
I have 2 buttons on my Form.
My question is if button1 can activate button2 in any way.
Is it possible to write any code inside button1 that will execute/activate the code inside button2 ?
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 351
Reputation: Radical Edward has a spectacular aura about Radical Edward has a spectacular aura about Radical Edward has a spectacular aura about 
Solved Threads: 62
Radical Edward's Avatar
Radical Edward Radical Edward is offline Offline
Posting Whiz

Re: Button activate other button

 
0
  #2
May 6th, 2008
If the code is run from more than one event, you should refactor it into a method:
  1. void button1_Click(Object^ sender, EventArgs^ e)
  2. {
  3. // Stuff for button 1
  4.  
  5. Button2Stuff();
  6. }
  7.  
  8. void button2_Click(Object^ sender, EventArgs^ e)
  9. {
  10. Button2Stuff();
  11. }
  12.  
  13. void Button2Stuff()
  14. {
  15. // Stuff for button 2
  16. }
You can also fire an event handler directly since it's just another method:
  1. void button1_Click(Object^ sender, EventArgs^ e)
  2. {
  3. // Stuff for button 1
  4.  
  5. button2_Click(this, EventArgs::Empty);
  6. }
  7.  
  8. void button2_Click(Object^ sender, EventArgs^ e)
  9. {
  10. // Stuff for button 2
  11. }
Last edited by Radical Edward; May 6th, 2008 at 2:03 pm.
If at first you don't succeed, keep on sucking until you do succeed.
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 517
Reputation: Jennifer84 is an unknown quantity at this point 
Solved Threads: 1
Jennifer84 Jennifer84 is offline Offline
Posting Pro

Re: Button activate other button

 
0
  #3
May 6th, 2008
Thank you. I will play around and see what I can do...
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



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

©2003 - 2009 DaniWeb® LLC