我制作了MyTextMain
自定义控件
我添加了属性:
Public Property PressedEscape As Boolean = False
和
Private Sub MyTextMain_KeyUp (ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyUp
If e.KeyCode = Keys.Escape Then Me.PressedEscape = True
End Sub
但是,当我向任何新表单添加TextBox
时,重点是该控件,我按ESC
, 属性不会更改。
我尝试使用True和False的表单的KeyPreview
属性。
错误在哪里?
答案 0 :(得分:1)
覆盖自定义TextBox控件中的ProcessCmdKey:
Protected Overrides Function ProcessCmdKey(ByRef msg As Message, keyData As Keys) As Boolean
If keyData = Keys.Escape Then
Me.PressedEscape = True
End If
Return MyBase.ProcessCmdKey(msg, keyData)
End Function
让PressedEscape成为一个属性似乎是一个奇怪的选择。我会根据你正在做的事情重新思考。