始终激活Windows应用程序

时间:2014-11-24 06:11:31

标签: vb.net

我创建了一个Windows应用程序,我在form1中有一个文本框。如果我运行应用程序它工作正常,

我已设置textbox_lostfocus事件 -

Private Sub txtCardID_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtCardID.LostFocus

    txtCardID.Focus()

End Sub

表格停用事件 -

Private Sub frmPlay_Deactivate(sender As Object, e As EventArgs) Handles MyBase.Deactivate

    txtCardID_LostFocus(sender, e)
    Me.Activate()
End Sub

但我的问题是当我点击其他应用程序说 - 画,或其他变得激活的应用程序和我的应用程序丢失焦点

当我点击我的表单时,它会激活并运行

我需要始终激活我的表单以及点击该值的键应该输入文本框

1 个答案:

答案 0 :(得分:0)

阅读帖子" How can I prevent other apps from stealing the focus?"

或者试试这个,如果你的表单中有多个控件不是txtCardID:

Public Class Form1

    Private fin As Boolean

    Private Sub Form1_Deactivate(sender As Object, e As System.EventArgs) Handles Me.Deactivate

        Do
            Me.Activate()
            My.Application.DoEvents()
        Loop Until fin

    End Sub

    Private Sub Form1_FormClosing(sender As Object, e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        fin = True
    End Sub

End Class