views:

22

answers:

2

Hello, pretty new to vb and I want to get a tab control working. so far I have the form with a tab control on it, there are 5 tabs each with a label contained in the tab-page. I want to have a button outside of the tab that changes on the form. when clicked the button will change the text of the label based on which tab is currently selected. I know it should be possible to do this, I'm not too sure where to start.

+1  A: 

I am assuming you are working with a windows form application.

If so the tabs are a collection of tabpage controls and the text is the Tabpage.text property. To change the text you would need to get a reference to the correct tabpage and then set its text to the new value.

After you edit and a reread I am unsure what you want to happen. If you want to change button label in response to tab change or Tab label in response to button. If you want to respond to tab change then use

Private Sub Control1_TabIndexChanged(sender as Object, e as EventArgs) _ Handles Control1.TabIndexChanged

Button1.Text = "You are on tab :" + Control1.SelectedTab.Text

End Sub

Roadie57
I have a label control on each tab (5 labels). I want the button to change the label.text based on which of the 5 tabpages is currently selected
ajoe
Why do you have a label for each tab? You should be able to do what Roadie said and change it based on the index.
Terry
+1  A: 

You need to find the label control back on the active tab page. The cleanest way to do this is to create an array that has a reference to each label. Like this:

Public Class Form1
    Private Labels() As Label

    Public Sub New()
        InitializeComponent()
        Labels = New Label() { Label1, Label2 }
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Labels(TabControl1.SelectedIndex).Text = DateTime.Now.ToString()
    End Sub
End Class
Hans Passant