如何使用vb wpf检测删除按钮 [英] How to detect delete button using vb wpf

查看:42
本文介绍了如何使用vb wpf检测删除按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我曾在窗口窗体中使用过此代码...但似乎无法使用WPF:



i once used this code within window forms...but seems not to work with WPF:

Private Sub frm_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
        If e.KeyCode = Keys.Delete Then MsgBox("You have pressed delete")
    End Sub





我应该怎么做才知道.thnkx



Any idea of how i should do it.thnkx

推荐答案

请确保 this.KeyPreview = true; 设置正确。



另请注意,在WPF中,事件是冒泡或通过隧道传输的。因此,事件有时不会处理您希望处理的事件。

通过冒泡或隧道基本的WPF事件 [ ^ ]以获得更好的解释。



此外, PreviewKeyDown 是一个隧道事件,在视觉树的顶部即窗口级别更容易处理。
Please ensure that this.KeyPreview = true; is set correctly.

Also note that in WPF events are bubbled or tunneled. As a result, events are sometimes not handled where you expect them to be handled.
Go through To bubble or tunnel basic WPF events[^] for a better explanation.

Further, PreviewKeyDown is a tunneling event and is easier handled at the top of the visual tree i.e. window level.


KeyEventArgs中有e.Key属性WPF



There is e.Key property for KeyEventArgs in WPF

Console.WriteLine(e.Key.ToString());





希望这有帮助!



Hope this helps!


这篇关于如何使用vb wpf检测删除按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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