如何实现从鼠标禁用的文本框,单击vb.net [英] How to enable a disabled textbox from mouse click vb.net
本文介绍了如何实现从鼠标禁用的文本框,单击vb.net的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
简单的如何使这是通过点击它禁用的文本框?这是怎么做的?
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
这篇关于如何实现从鼠标禁用的文本框,单击vb.net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文