In my forms I have a tab control containing two pages, in tabpage1 (list view) tabpage2 (gridview) and a several buttons. my problem now is how to know that if the user hit a button then locate the active control or tabpage eaither tabpage1 or tabpage2. I intent that the user chosen either the tabpage1 or tabpage2 then click the ok button, after click the ok button then I want to know the previous active control or tabpage. Please help me

I am a newbie with this environment, I am using vb 2005. I have no other resources but only this forums. I have read some help and tutorial but sometimes very hard to understand

Thanks a lot

Use a variable to keep track of the last tab clicked. I used a tab control with two tabs, a button on each page and a button on the form. Here is the code:

Public Class Form1
    Dim TabPage As Integer = 1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Select Case TabPage
            Case 1
            Case 2
        End Select
    End Sub

    Private Sub TabControl1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TabControl1.SelectedIndexChanged
        Dim tc As TabControl = sender
        Dim txt As String = tc.SelectedTab.ToString
        If txt.IndexOf("{TheFirstPageText") > -1 Then
            TabPage = 1
            TabPage = 2
        End If
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        MessageBox.Show("Button 2 clicked")
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        MessageBox.Show("Button 3 clicked")
    End Sub

End Class

hi waynes, thank you so much for your immediate replied. This will help too much for me as a beginner.


This question has already been answered. Start a new discussion instead.