Windows窗体自定义控件:没有UIPermissionWindow.AllWindows的焦点和光标键 [英] Windows Forms custom control: focus and cursor keys without UIPermissionWindow.AllWindows

查看:241
本文介绍了Windows窗体自定义控件:没有UIPermissionWindow.AllWindows的焦点和光标键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为Windows Forms编写一个自定义控件(一个文本编辑器),它应该包含以下功能:


  • 获取键盘焦点,当您用鼠标点击它时
  • 可以看到所有的键盘输入(包括光标键),当它有焦点时

  • 可以在 UIPermissionWindow.SafeTopLevelWindows (即它不应该需要 UIPermissionWindow.AllWindows )运行在半可信环境中。 / li>


有没有这样做的例子?

有些方法我可能想要使用像 Control.Focus() Control.InInputKey(),require UIPermissionWindow.AllWindows



是否有任何其他方式来获取/实现功能,而不使用这些方法? b
$ b

内置的TextBox控件具有此功能(获取焦点并处理光标键)。

解决方案公共类UserControl1
继承文本框

私人小组UserControl1_GotFocus(BYVAL发件人作为对象,BYVAL e作为System.EventArgs)处理我。 GotFocus

End Sub

Private Sub UserControl1_KeyDown(ByVal sender As Object,ByVal e As System.Windows.Forms.KeyEventArgs)处理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)处理Me.KeyPress
Debug.WriteLine(pressed)
Debug.WriteLine(e.KeyChar)
End Sub
End Class


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 to 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

这篇关于Windows窗体自定义控件:没有UIPermissionWindow.AllWindows的焦点和光标键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆