鼠标单击vb.net时无法聚焦文本框

时间:2015-12-22 04:29:31

标签: vb.net

点击输入键时,我有多个文本框和光标移动。我在下面的代码中点击鼠标时没有聚焦:

Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
    Const WM_MOUSEFIRST As Integer =  &H200
    Const WM_LBUTTONDOWN As Integer =  &H201
    Const WM_LBUTTONUP As Integer =  &H202
    .
    .
    .

    Dim ownForm As Form = Me.FindForm()

    If Not ownForm IsNothing AndAlso Not ownForm.ActiveControl is Me Then
        If(m.Msg = WM_MOUSEFIRST OrElse _
           m.Msg = WM_LBUTTONDOWN OrElse _
           m.Msg = WM_LBUTTONUP OrElse _
           .
           .
           .)Then
        Else
            MyBase.WndProc(m)
        EndIf
    Else
        MyBase.WndProc(m)
    EndIf
End Sub

我在普通文件中写了上面的代码,可以从其他表单访问。所以问题来了,我想用鼠标点击一些文本框。我应该怎么写。我不能修改上面的代码,因为这是常见的。所以请给我建议如何写出适当的这种情况。

我尝试了这段代码并且没有关注:

Private Sub txt_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles txt.MouseDown
    txt.Focus()
End Sub

先谢谢...

0 个答案:

没有答案