Reputation: 757
How can I hide a button when a specific tab is clicked?
for example I have 4 tabs what should I do whenever I click tab 1 a certain button in my form will disappear?
i've tried using if(tabControl.SelectedIndex == 1){ button1.Visible = false; }
but it doesn't work. T_T
Upvotes: 1
Views: 437
Reputation: 83358
You could use the Click
event on that particular TabPage
yourTabControl.TabPages[1].Click += (s, e) => button1.Visible = false;
Just remember to show it again when the time is appropriate.
Or better yet, just listen for when the selected tab changes:
yourTabControl.SelectedIndexChanged += (s, e) => {
if (yourTabControl.SelectedIndex == 1)
button1.Visible = false;
} else {
button1.Visible = true;
}
};
Or more simply:
yourTabControl.SelectedIndexChanged += (s, e) =>
button1.Visible = yourTabControl.SelectedIndex != 1;
Upvotes: 2