开发者

Windows Forms custom control: focus and cursor keys without UIPermissionWindow.AllWindows

I want to write a custom control (a text editor) for Windows Forms, which should include the following functionality:

  • Gets the keyboard focus, when you click on it with the mouse
  • Sees all keyboard input (including cursor keys), when it has the focus,
  • Can run in a semi-trusted environment, with UIPermissionWindow.SafeTopLevelWindows (i.e. it shouldn't require UIPermissionWindow.AllWindows)

Is there any example of doing this?

Some of the methods which I might want to use, like Control.Focus() and Control.InInputKey(), require UIPermissionWindow.AllWindows.

Is there any other way t开发者_高级运维o get/implement the functionality, without using these methods?

The built-in TextBox control has this functionality (gets the focus and handles cursor keys).


Public Class UserControl1
    Inherits TextBox

    Private Sub UserControl1_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.GotFocus

    End Sub

    Private Sub UserControl1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
        Debug.WriteLine("downed")
        Debug.WriteLine(e.KeyValue)
        Debug.WriteLine(e.KeyCode)

    End Sub

    Private Sub UserControl1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Me.KeyPress
        Debug.WriteLine("pressed")
        Debug.WriteLine(e.KeyChar)
    End Sub
End Class
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜