Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can't get TabControl_click to work

Status
Not open for further replies.

TonyScarpelli

Programmer
Jan 23, 2003
361
US
I have a form with a number of tab pages on it.

When I click on a particular tab, I want the for form's title to change.

I have the following code to test the idea, but it doesn't work. When I click on a tab the the following code doesn't run.

Private Sub TabControl_Click(ByVal sender As Object, _
ByVal e As System.EventArgs)
MsgBox(TabControl.SelectedTab.Name.ToString)
End Sub

Can some give me a clue as to why this code isn't running?

Thanks.


Tony Scarpelli
Clinical Engineering Dept.
Maine Medical Center
Portland, Maine 04102
 
I have used the tab control's SelectedIndexChanged to determine when a certain tab page is clicked on.

Andrea
 
How do you program that into the form?

Is this an event that the form can catch?

Thanks.


Tony Scarpelli
Clinical Engineering Dept.
Maine Medical Center
Portland, Maine 04102
 
Here is an example.

Code:
Private Sub TabControl1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TabControl1.SelectedIndexChanged

        Select Case TabControl1.SelectedTab.Name
            Case "TabPage1"
                'do something
            Case "TabPage2"
                'do something else
        End Select

End Sub
 
As posted above is the correct method. In your particular case this is all that needs to be done:

Private Sub TabControl1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TabControl1.SelectedIndexChanged

Me.Text = TabControl1.SelectedTab.Text

End Sub


*just for the future you don't need to use the .ToString method on a property that is already in a string format
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top