开发者

SendKeys.Send("{HOME}"), vb.net

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.


{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)


Give the textbox a focus before the SendKeys

MaskedTextBox1.Focus()


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜