James
James

Reputation: 125

Setting Focus on a Tab

I have a tab in a windows form called Wafer Map that has three sub-tabs. The First sub-tab is the called Map and has a Load and Skip button. I am trying to set the focus on the Wafer sub-tab on the Load button click. This is the following code I have tried to use.

Private Sub Load_Wafer_Layout_Map_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Load_Wafer_Layout_Map.Click
    Wafer_Info.Enabled = True
    Wafer_Info.Show()
End Sub

The Wafer_Info.Enabled = True is used to enabled all of the controls on the Wafer tab and works properly when the button is clicked. I have tried using .Focus() and .Show() to bring focus to the next tab but I am not have any luck getting to switch. Anyone have any suggestions?

Upvotes: 3

Views: 40974

Answers (5)

LucianoB
LucianoB

Reputation: 1

One example to utilise

Private Sub BtnGoprint_Click(sender As System.Object, e As System.EventArgs) Handles BtnGoprint.Click If (txtggsett.Text.Length = "0") And (txtsunAR.Text.Length = "0") And (txtggsett.Text.Length = "0") Then

 MsgBox("Calculate first, then print," & vbCrLf & "DISABLED TO AVOID ERRORS", MsgBoxStyle.Exclamation, "NESSUN CALCOLO")
        TabControl1.SelectedIndex = 0
    Else
        TabControl1.SelectedIndex = 11
        Btnprint.Show()
        Btnprint.Focus()

Upvotes: 0

Joshua
Joshua

Reputation: 31

I came across this thread as i was looking for a solution to my own focus issue. I have a TabControl with many TabPages. Each TabPage is set to auto scroll due to overflowing content. The problem I ran into was the mouse scroll wheel would not function if the TabPage did not have focus. Since there is not an event for each tab click it made setting focus to each TabPage a challenge. It was not hard, but a challenge none the less. So, here is my code (assuming auto scroll true).

On form load sets focus to main TabPage:

Private Sub frmParent_Load(sender As Object, e As System.EventArgs) Handles Me.Load
    TabControl1.TabPages(0).Focus()
End Sub

Sets focus to current TabPage by getting the index then setting focus. This is triggered by TabControl1.SelectedIndexChange event.

Private Sub TabControl1_SelectedIndexChanged(sender As Object, e As System.EventArgs) Handles TabControl1.SelectedIndexChanged
    Dim intTabIndex As Integer = TabControl1.SelectedIndex
    TabControl1.TabPages(intTabIndex).Focus()
End Sub

I hope someone find this useful. It was very useful for me.

Joshua

Upvotes: 3

James
James

Reputation: 125

The code that worked for me is Tab_WaferMap.SelectTab(1). Tab_WaferMap is my main tab and the 1 is the index of the sub tab I wanted to show

Upvotes: 3

Matt Wilko
Matt Wilko

Reputation: 27322

You can also set the Selected Index of the tab (and sub-tab) using a (zero based) numeric value:

TabParent.SelectedIndex = 3
TabSub.SelectedIndex=2

Upvotes: 0

George Johnston
George Johnston

Reputation: 32258

Just set it:

tabControl.SelectedTab = yourTab

On the Tab Controls Tab Pages, just ensure you name the tab you are attempting to reference. Additionally, see MSDN TabControl.SelectedTab

Upvotes: 7

Related Questions