title: C# How to terminate application.run()
body: <p>I would like to know, how to terminate a program using, for example, the escape key. 
  In general, what I have to do to stop it after the application.run(..)? </p>
  
  <p>How can I insert this</p>
  
  <pre><code> private void myForm_KeyUp(object sender, System.Windows.Forms.KeyEventArgs e) { 
             if (e.KeyCode == Keys.Escape) { 
                 Application.Exit(); 
              } 
          } 
  </code></pre>
  
  <p>in the code below</p>
  
  <pre><code>static void Main()
      {
  
          using (WinForm new_form = new WinForm())
          {
              new_form.InitializeComponent();
              new_form.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.Opaque, true);
              new_form.InitializeDevice();
              new_form.LoadSurfaces();
              new_form.Set3D();
              Application.Run(new_form);
           }
  </code></pre>
  
  <p>}</p>