Reputation: 2629
I have an application with 2 tabs, and a toolstrip button "open test image". How can I enable this toolstrip button only when Tab 2 [analysis] is open ?
Upvotes: 1
Views: 37
Reputation: 17370
This disables the button when the form loads:
private void Form1_Load(object sender, EventArgs e)
{
btnOpen.Enabled = false;
}
Then you can re-enable it by capturing the index of the tab that was clicked:
private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
{
btnOpen.Enabled = ((TabControl)sender).SelectedIndex == 1;
}
Upvotes: 2
Reputation: 81610
You can use the Selected event of the TabControl:
private void tabControl1_Selected(object sender, TabControlEventArgs e) {
toolStripButton1.Enabled = (e.TabPage.Name == tabPage2.Name);
}
Of course, it probably makes more sense to put the button inside the TabPage, then you wouldn't have to worry about this issue.
Upvotes: 2