tags:

views:

23

answers:

2

Best to explain with an example.

TabControl has Tab1 and Tab2.

I'm trying to make it so when Tab1 is selected, Button1 is visible and stays visible. When Tab2 is selected, Button1 is invisible and stays invisible. I need it to work when the Tab is clicked, not when the content area of the Tab is clicked.

Thank you.

A: 

One way you can do that is to add an "onclickclick" function to each tab head that sets the visibility style of the buttons you're trying to show / hide.

Avitus
When I try to do that, it only does it when I click the content area of the tab, not the tab itself.
VBeginner
+1  A: 

Try this:

Private Sub TabControl1_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles TabControl1.MouseClick
        Me.Button1.Visible = TabControl1.SelectedTab Is TabPage1
        Me.Button2.Visible = TabControl1.SelectedTab Is TabPage2
End Sub

Btw, why do you need that? If Button1 is on TabPage 1 and Button2 is on TabPage2 they will appear/hide automatically.

Regards

Tim Schmelter
The SelectedIndexChanged event would be more appropriate. But yes, that button belongs on the tab page.
Hans Passant