simple Visual C# / WPF app question…..? | Programming, .NET, Silverlight & More

simple Visual C# / WPF app question…..?

i have a WPF application i created in C#….what code do I need to add to WIndow.xaml.cs to make the programme close when i hit "Esc"????

thanks,
–nick

i’m brand new to c# programming but i think you need a keyboard event handler mapped to the esc key (make sure the event is mapped to the window not to a grid etc, and then just add the code this.Close();

try this(get the event from visual studio)

private void Window_KeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Escape)
{
this.Close();
}
}

No TweetBacks yet. (Be the first to Tweet this post)

One Response

  1. Mark Says:

    i’m brand new to c# programming but i think you need a keyboard event handler mapped to the esc key (make sure the event is mapped to the window not to a grid etc, and then just add the code this.Close();

    try this(get the event from visual studio)

    private void Window_KeyDown(object sender, KeyEventArgs e)
    {
    if (e.Key == Key.Escape)
    {
    this.Close();
    }
    }
    References :

Leave a Comment

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.