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)
October 1st, 2009 at 7:56 pm
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 :