7

How do I determine which TabPage is currently active?

 3 years ago
source link: https://www.codesd.com/item/how-do-i-determine-which-tabpage-is-currently-active.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

How do I determine which TabPage is currently active?

advertisements

I want to learn which tabpage in my window is active. My aim is something like this:

  if Tabpage1 is active then
   .....
  end if

  if Tabpage2 is active then
  ...
  end if

I will write it on form closing.


You have to query the container control (the TabControl control) for this information, not the individual TabPage controls that it hosts.

And you have two options for doing so, depending on the type of information that you wish to receive. You can either use the SelectedIndex property, which returns the zero-based index of the currently selected tab page, or you can use the SelectedTab property, which returns an instance of the TabPage class representing the currently selected tab page.

Code sample:

If myTabControl.SelectedIndex = 1 Then
    ' Do something for the first tab page
ElseIf myTabControl.SelectedIndex = 2 Then
    ' Do something for the second tab page
Else
    ' Uh-oh! One of the other tab pages that you didn't
    ' mention in your question is selected!
End If

If myTabControl.SelectedTab = myFirstTabPage Then
    ' Do something for the first tab page
ElseIf myTabControl.SelectedTab = mySecondTabPage Then
    ' Do something for the second tab page
Else
    ' Uh-oh! One of the other tab pages that you didn't
    ' mention in your question is selected!
End If




About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK