SendKeys.Send(“{HOME}”),vb.net
我在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我正在使用 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
{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)
在 SendKeys 之前给文本框一个焦点
Give the textbox a focus before the SendKeys