Click here to Skip to main content
15,499,967 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I have been creating a Calculator in C# and it’s a WPF Application. I have enabled a few keys like numbers, addition key, multiplication key etc. As I have enabled few keys only, the user cannot exit the application using alt+F4. I have used PreviewKeyDown Even and I have handled other irrelevant keys. Is there a solution to enable alt+F4 ?
Thanks in advance.

Here is a piece of my code:

C#
private void Window_PreviewKeyDown(object sender, KeyEventArgs e)
        {

            switch (e.Key)
            {
                case Key.D0: Number0_Click(sender, e); break;
                case Key.D1: Number1_Click(sender, e); break;
                case Key.D2: Number2_Click(sender, e); break;
                .
                .
                .
                case Key.NumPad6: Number6_Click(sender, e); break;
                case Key.NumPad7: Number7_Click(sender, e); break;
                case Key.NumPad8: Number8_Click(sender, e); break;
                case Key.NumPad9: Number9_Click(sender, e); break;


                default:
                    e.Handled = true;
                    break;
            }
Posted
Updated 1-Apr-14 0:14am
v2

I don't know about WPF. I guess the issue is due to e.Handled = true; which blocks the event from executing the default behavior i.e. for Alt+F4 close the window.
 
Share this answer
 
Change the default code:
C#
default:
    e.Handled = false;
    break;

If you return true for everything you don't do anything with, none of those will ever work...
 
Share this answer
 

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


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