SendKeys.Send(“{HOME}”),vb.net

发布于 2024-08-20 20:14:38 字数 517 浏览 4 评论 0原文

我在 MaskedTextBox 中使用 SendKeys.Send("{HOME}") 在文本为空时将光标移至文本框的开头。

当我尝试关闭项目时,如果应用程序没有焦点,它就会冻结。

在调用 SendKeys 之前,如何将此应用程序置于焦点位置?

Public Class Form1

Private Sub MaskedTextBox1_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles MaskedTextBox1.GotFocus
    Try
        SendKeys.Send("{HOME}")
    Catch ex As InvalidOperationException
        ' Do nothing
    End Try
End Sub
End Class

之后,它应该将焦点集中到前一个应用程序并关闭。

I am using SendKeys.Send("{HOME}") in a MaskedTextBox to bring the cursor to the beginning of the textbox when the text is empty.

When I try to close the project the application freezes if it doesn't have focus.

How do I put this application in focus before I call SendKeys?

Public Class Form1

Private Sub MaskedTextBox1_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles MaskedTextBox1.GotFocus
    Try
        SendKeys.Send("{HOME}")
    Catch ex As InvalidOperationException
        ' Do nothing
    End Try
End Sub
End Class

After that, it should give focus to the previous application and close.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

浪荡不羁 2024-08-27 20:14:39

我正在使用 Visual Basic 登录,但它不在运行时运行。突出显示 SENDKEYS 为违规者。这是我的代码

Private Sub cmdOK_Click()
'检查密码是否正确
如果 txtPassword = "密码" 那么
'将代码放在这里以传递
'调用子程序成功
'设置全局变量是最简单的
登录成功 = True
我隐藏
别的
MsgBox "密码无效,请重试!", , "登录"
txt密码.SetFocus
发送键“{HOME}+{END}”
结束如果
结束子

I am using visual basic login and it it is not running at run-time. Highlights SENDKEYS as the offender. Here is my code

Private Sub cmdOK_Click()
'check for correct password
If txtPassword = "password" Then
'place code to here to pass the
'success to the calling sub
'setting a global var is the easiest
LoginSucceeded = True
Me.Hide
Else
MsgBox "Invalid Password, try again!", , "Login"
txtPassword.SetFocus
SendKeys "{HOME}+{END}"
End If
End Sub

寂寞陪衬 2024-08-27 20:14:38

{HOME} 就像按 home 键,这不会带来焦点。

获得焦点的最佳方法是调用文本控件上的 focus 方法。就像文本框.focus();

请包含您的页面代码,或页面内容的示例。

MaskedTextBox1.选择(0,0)

{HOME} is like hitting the home key, this will not bring focus.

best thing to do to bring focus is to call the focus method on the text control. like textbox.focus();

Please include your page code, or an example of what is on the page.

MaskedTextBox1.Select(0,0)

酒中人 2024-08-27 20:14:38

在 SendKeys 之前给文本框一个焦点

MaskedTextBox1.Focus()

Give the textbox a focus before the SendKeys

MaskedTextBox1.Focus()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文