如何实现从鼠标禁用的文本框,单击vb.net鼠标、单击、如何实现、文本框

2023-09-06 15:32:54 作者:对面、说再见

简单的如何使这是通过点击它禁用的文本框?这是怎么做的?

Simple how to enable a Textbox which is disabled by clicking on it? how is this done?

我的code不起作用

Private Sub Textbox1_MouseClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Textbox1.MouseClick
    Textbox1.Enabled = True
End Sub

谁能帮我。

我必须诉诸跟踪鼠标点击和X,文本框与计时器等的Y位置..没有事件从点击它解雇了?

Do I have to resort to tracking the mouse clicks and X,Y positions of textbox with timers etc.. no events are fired from clicking it?

推荐答案

您可以使用IMessageFilter来捕获WM_LBUTTONDOWN消息,然后检查是否光标在文本框之内......是这样的:

You can use IMessageFilter to trap WM_LBUTTONDOWN messages and then check to see if the cursor is within the TextBox...something like:

Public Class Form1

    Private WithEvents filter As New MyFilter

    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        TextBox1.Enabled = False
        Application.AddMessageFilter(filter)
    End Sub

    Private Sub filter_LeftClick() Handles filter.LeftClick
        Dim rc As Rectangle = TextBox1.RectangleToScreen(TextBox1.ClientRectangle)
        If rc.Contains(Cursor.Position) AndAlso Not TextBox1.Enabled Then
            TextBox1.Enabled = True
            TextBox1.Focus()
        End If
    End Sub

    Private Class MyFilter
        Implements IMessageFilter

        Public Event LeftClick()
        Private Const WM_LBUTTONDOWN As Integer = &H201

        Public Function PreFilterMessage(ByRef m As System.Windows.Forms.Message) As Boolean Implements System.Windows.Forms.IMessageFilter.PreFilterMessage
            Select Case m.Msg
                Case WM_LBUTTONDOWN
                    RaiseEvent LeftClick()

            End Select
            Return False
        End Function

    End Class

End Class