Close Form with Pressing X key : Key Event « Event « C# / C Sharp






Close Form with Pressing X key




using System;
using System.Drawing;
using System.Windows.Forms;
   
class ExitOnX: Form
{
     public static void Main()
     {
          Application.Run(new ExitOnX());
     }
     public ExitOnX()
     {
          Text = "Exit on X";
     }
     protected override void OnKeyDown(KeyEventArgs kea)
     {
          if (kea.KeyCode == Keys.X)
               Close();
     }
}
           
       








Related examples in the same category

1.Event system explained in detail
2.Check KeyCode from KeyEventArgs
3.Shift key pressedShift key pressed
4.Control Key pressedControl Key pressed
5.Alt key pressedAlt key pressed
6.Get Async Key StateGet Async Key State
7.Get Key action informationGet Key action information
8.Displaying information about the key the user pressedDisplaying information about the key the user pressed
9.Displays a key pressed by the userDisplays a key pressed by the user
10.Full screen and KeyEvent and MouseEvent
11.Key PressKey Press
12.Key Timer Key Timer
13.Keyboard SampleKeyboard Sample