Reputation: 18167
This page indicates that TabPage has a GotFocus event, but in Visual Studio 2008 I don't see that option on the TabPage (it says it is inherited from the control, i.e. the TabControl).
What event would I use to write some code that runs each time a user clicks on a different tab? Would I use the GotFocus of the TabControl - but in that case, when user switches to different tabs doe sthe GotFocus fire again (and pass me the tabname as a variable?)
Upvotes: 0
Views: 3495
Reputation: 1
I solved this same problem by adding this to a frmName_Load(object sender, System.EvenArgs e)
method.
this.btnInUse.Visible = false; //This sets the button to be invisible.
Then in the method:
private void tabControl1_SelectedIndexChanged(object sender, System.EventArgs e)
I added some code to turn on the control when the tab was selected and off when it was not selected.
if (this.tabControl1.SelectedTab.Name == "tabOTS")
{
btnInUse.Visible = true;
}
else
{
btnInUse.Visible = false;
}
Upvotes: 0
Reputation: 1486
Tabcontrol in Windows.Forms has SelectedIndex Changed-Event and SelectedTab Property.
So registering TabControl.SelectedIndexChanged ask for the TabControl.SelectedTab is all you need.
Upvotes: 2