Joel
Joel

Reputation: 83

How do you PerformClick(); for a button on a different tab?

I'm using Visual c# express 2010, I have 3 tabs and on the first tab there is a button that exits the program. I'm trying to call that button click on the 2nd and 3rd tab with

btnExit.PerformClick(); 

but since it isn't visible nothing happens. How would I call the invisible button click?

any help would be appreciated

EDIT: Thanks for the replies, the two answers work great but I found a way that I think is easier and better.

instead of systematically changing tabs or calling a whole different method, I did this

btnExit_Click(sender, e);

I can put that in any other button click and it works great, very simple to.

Upvotes: 4

Views: 4965

Answers (2)

MNIK
MNIK

Reputation: 1619

I think it's better to create a method that actually has the code to exit the program, and call that method from btnExit click event and also other buttons click event, than PerformClick of the exit button.

void ExitApplication()
{
   // code to exit the application
}

protected void btnExit_Click(object sender, EventArgs e)
{
   ExitApplication();
}
protected void ButtonInOtherTab_Click(object sender, EventArgs e)
{
   ExitApplication();
}

This way it's easier to read and understand.

Upvotes: 6

Teoman Soygul
Teoman Soygul

Reputation: 25732

myTabs.SelectedTab = specificTab;
btnExit.PerformClick(); 

Upvotes: 2

Related Questions