Close Form with Pressing X key

image_pdfimage_print
   




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();
     }
}
           
          


This entry was posted in Event. Bookmark the permalink.