vb.net 在选项卡上设置焦点
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6667350/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Setting Focus on a Tab
提问by James
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.
我有一个名为 Wafer Map 的窗口形式的选项卡,它具有三个子选项卡。第一个子选项卡称为地图,有一个加载和跳过按钮。我正在尝试将焦点设置在“加载”按钮单击上的“晶圆”子选项卡上。这是我尝试使用的以下代码。
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?
Wafer_Info.Enabled = True 用于启用 Wafer 选项卡上的所有控件,并在单击按钮时正常工作。我曾尝试使用 .Focus() 和 .Show() 将焦点带到下一个选项卡,但我没有任何运气切换。有人有什么建议吗?
回答by George Johnston
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 MSDNTabControl.SelectedTab
在 Tab Controls Tab Pages 上,只需确保您命名要尝试引用的选项卡。此外,请参阅MSDN TabControl.SelectedTab
回答by James
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
对我有用的代码是Tab_WaferMap.SelectTab(1)
. Tab_WaferMap 是我的主选项卡,1 是我想显示的子选项卡的索引
回答by Joshua
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).
我在寻找解决我自己的焦点问题的方法时遇到了这个线程。我有一个带有许多 TabPage 的 TabControl。由于内容溢出,每个 TabPage 都设置为自动滚动。我遇到的问题是,如果 TabPage 没有焦点,鼠标滚轮将不起作用。由于每个选项卡单击都没有事件,因此将焦点设置到每个 TabPage 是一个挑战。这并不难,但仍然是一个挑战。所以,这是我的代码(假设自动滚动为真)。
On form load sets focus to main TabPage:
在表单加载时将焦点设置到主 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.
通过获取索引然后设置焦点将焦点设置到当前 TabPage。这是由 TabControl1.SelectedIndexChange 事件触发的。
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
约书亚
回答by Matt Wilko
You can also set the Selected Indexof the tab (and sub-tab) using a (zero based) numeric value:
您还可以使用(从零开始的)数值设置选项卡(和子选项卡)的选定索引:
TabParent.SelectedIndex = 3
TabSub.SelectedIndex=2