简体   繁体   English

vb.net:将重点放在嵌套的自定义控件上

[英]vb.net: setting focus on nested custom controls

I have a nested custom control that I need to set focus on. 我有一个嵌套的自定义控件,需要重点关注。 I have it all internally wired up to automatically set the focus when the form loads, but when it comes up on screen, the designated accept button for the parent form is in focus instead. 我将所有这些都内部连接起来,以便在加载表单时自动设置焦点,但是当它出现在屏幕上时,父表单的指定接受按钮将变为焦点。 Even when is disassociate the accept button it still does not set correctly. 即使取消了接受按钮的关联,它仍然无法正确设置。 How can I ensure my desired control gets focus. 如何确保所需的控件得到关注。

I think what you're asking is that you would like to make a textbox (or button, etc) on a user control have focus when the form loads. 我想您要问的是,您希望在加载表单时使用户控件上的文本框(或按钮等)具有焦点。 Try setting the ActiveControl of the user control to the textbox (or which ever control) and then calling focus on it. 尝试将用户控件的ActiveControl设置为文本框(或哪个控件),然后对其进行调用。 For example: 例如:

Private Sub myUserControl_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
   ActiveControl = myTextbox
   myTextbox.Focus()
End Sub

Set the tab order. 设置标签顺序。 If your custom control is on the same level as buttons (has the same parent), make sure your control and any containter it is in has tab index 0. 如果您的自定义控件与按钮处于同一级别(具有相同的父级),请确保您的控件及其所在的任何容器中的制表符索引均为0。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM