Click here to Skip to main content
15,887,262 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i once used this code within window forms...but seems not to work with WPF:

VB
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


Any idea of how i should do it.thnkx
Posted
Updated 30-Jan-13 5:16am
v2

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.
 
Share this answer
 
v3
There is e.Key property for KeyEventArgs in WPF

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


Hope this helps!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900