none
[Help] Detect if you have changed a TabControl RRS feed

  • Question

  • Hello friends,

    I would like to know what is the event of a TabControl to detect that TabPage is selected.

    What I want to do is that when a particular TabPage is selected, the ImageIndex will modify it for another image and in case a particular TabPage is not selected, put another image.

    How could I do it?

    Thank you
    • Edited by Symantecc Wednesday, May 24, 2017 8:33 PM
    Wednesday, May 24, 2017 8:23 PM

Answers

  • This might be more of what you want:

    Option Strict On
    Option Explicit On
    Option Infer Off
    
    Public Class Form1
        Private Sub _
            Form1_Load(ByVal sender As System.Object, _
                       ByVal e As System.EventArgs) _
                       Handles MyBase.Load
    
    
    
        End Sub
    
        Private Sub _
            TabControl1_Selecting(sender As Object, _
                                  e As System.Windows.Forms.TabControlCancelEventArgs) _
                                  Handles TabControl1.Selecting
    
            ' This event is raised when the tab page is
            ' being changed but you can stop that if you
            ' want:
    
            e.Cancel = True
    
        End Sub
    
        Private Sub _
            TabControl1_SelectedIndexChanged(sender As Object, _
                                             e As System.EventArgs) _
                                             Handles TabControl1.SelectedIndexChanged
    
            ' This event is raised once the tab page
            ' has been changed.
    
        End Sub
    End Class


    "A problem well stated is a problem half solved.” - Charles F. Kettering

    • Marked as answer by Symantecc Friday, May 26, 2017 7:54 PM
    Wednesday, May 24, 2017 9:01 PM

All replies

  • Hello friends,

    I would like to know what is the event of a TabControl to detect that TabPage is selected.

    What I want to do is that when a particular TabPage is selected, the ImageIndex will modify it for another image and in case a particular TabPage is not selected, put another image.

    How could I do it?

    Thank you

    To know if the TabControl is selected, use the TabControl.Selected event.

    As for knowing the TabPage, you can use the TabControl.SelectedTab property.


    "A problem well stated is a problem half solved.” - Charles F. Kettering

    Wednesday, May 24, 2017 8:38 PM
  • This might be more of what you want:

    Option Strict On
    Option Explicit On
    Option Infer Off
    
    Public Class Form1
        Private Sub _
            Form1_Load(ByVal sender As System.Object, _
                       ByVal e As System.EventArgs) _
                       Handles MyBase.Load
    
    
    
        End Sub
    
        Private Sub _
            TabControl1_Selecting(sender As Object, _
                                  e As System.Windows.Forms.TabControlCancelEventArgs) _
                                  Handles TabControl1.Selecting
    
            ' This event is raised when the tab page is
            ' being changed but you can stop that if you
            ' want:
    
            e.Cancel = True
    
        End Sub
    
        Private Sub _
            TabControl1_SelectedIndexChanged(sender As Object, _
                                             e As System.EventArgs) _
                                             Handles TabControl1.SelectedIndexChanged
    
            ' This event is raised once the tab page
            ' has been changed.
    
        End Sub
    End Class


    "A problem well stated is a problem half solved.” - Charles F. Kettering

    • Marked as answer by Symantecc Friday, May 26, 2017 7:54 PM
    Wednesday, May 24, 2017 9:01 PM
  • Hi Symantecc,

    According to you description, assuming you are looking out in Winform, there is a SelectedIndexChanged event for the tab.

    Now in it you could check for your specific tab and proceed with the logic.

    Private Sub TabControl1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles TabControl1.SelectedIndexChanged
            If TabControl1.SelectedTab Is TabControl1.TabPages("TabPage1") Then
                MessageBox.Show("Page selected")
            End If
        End Sub

    Best Regards,

    Cherry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, May 25, 2017 7:06 AM
    Moderator
  • Symantec,

    The Tabcontrol has some weird behaviour, which is in it already from the beginning. However, you can go around it. 

    The best website for the webcontrol is this one, there are all your problems described with a solution.

    http://dotnetrix.co.uk/tabcontrol.htm


    Success
    Cor

    Thursday, May 25, 2017 7:53 AM