Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 386
Joel Avatar asked Feb 24 '23 02:02

Joel


2 Answers

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.

like image 180
MNIK Avatar answered Mar 06 '23 23:03

MNIK


myTabs.SelectedTab = specificTab;
btnExit.PerformClick(); 
like image 26
Teoman Soygul Avatar answered Mar 06 '23 23:03

Teoman Soygul