简体   繁体   English

如何在vb.net中聚焦特定的文本框

[英]how to focus a specific textbox in vb.net

I'm making a desktop application in vb.net. 我正在vb.net中制作桌面应用程序。 When I click the back button (placed by me) on any form it hides current form and shows previous form but when i go again to the form from which i had hit back button then the focus cue still remains on the back button but I want the focus to be on the first textbox on that form or any specific button on which I want.....How can i achieve this... 当我在任何表单上单击“后退”按钮(由我放置)时,它会隐藏当前表单并显示以前的表单,但是当我再次转到单击“后退”按钮的表单时,焦点提示仍保留在“后退”按钮上,但是我想要重点放在该表单的第一个文本框或我想要的任何特定按钮上.....我如何实现这一目标...

I have already used some code to shift focus from one textbox to another when i press enter key...but it doesn't work in the above mentioned case....I'm using vb.net in visual studio 2005... 我已经使用了一些代码来在按Enter键时将焦点从一个文本框切换到另一个文本框...但是在上述情况下不起作用......我在Visual Studio 2005中使用vb.net。 。

This is the code i'm using for shifting focus among textboxes 这是我用于在文本框之间转移焦点的代码

Private Sub party_code_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles party_code.KeyDown
    If e.KeyData = Keys.Return Then
        party_name.Focus()
    End If
End Sub

Can anyone help me on this???? 谁可以帮我这个事????

You need to add a handler for either the form's Activated event: 您需要为表单的Activated事件添加一个处理程序:

Private Sub Form1_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Activated
    party_name.Focus()
End Sub

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

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