954,500 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Button activate other button

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 ?

Jennifer84
Posting Pro
564 posts since Feb 2008
Reputation Points: 10
Solved Threads: 1
 

If the code is run from more than one event, you should refactor it into a method:

void button1_Click(Object^ sender, EventArgs^ e)
{
  // Stuff for button 1

  Button2Stuff();
}

void button2_Click(Object^ sender, EventArgs^ e)
{
  Button2Stuff();
}

void Button2Stuff()
{
  // Stuff for button 2
}

You can also fire an event handler directly since it's just another method:

void button1_Click(Object^ sender, EventArgs^ e)
{
  // Stuff for button 1

  button2_Click(this, EventArgs::Empty);
}

void button2_Click(Object^ sender, EventArgs^ e)
{
  // Stuff for button 2
}
Radical Edward
Posting Pro
545 posts since May 2008
Reputation Points: 361
Solved Threads: 97
 

Thank you. I will play around and see what I can do...

Jennifer84
Posting Pro
564 posts since Feb 2008
Reputation Points: 10
Solved Threads: 1
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You