title: How to make a keypress form event in C#
body: <p>I'm trying to make a KeyPress event on a form, but in this line I got an error <code>MainWindow.KeyPress = new KeyPressEventArgs(Form_KeyPress);</code>, I read the Microsoft Docs about events in C#, but I don't get the idea.</p>
  
  <p>Do listeners like in Java exist in C# or not?</p>
  
  <p>My code:</p>
  
  <pre class="lang-cs prettyprint-override"><code>class PracticeEvent
  {
      static void Main(String[] args)
      {
          Form MainWindow = new Form();
          MainWindow.Text = "Practice";
          MainWindow.MaximizeBox = false;
          MainWindow.MinimizeBox = false;
          MainWindow.FormBorderStyle = FormBorderStyle.FixedSingle;
          MainWindow.StartPosition = FormStartPosition.CenterScreen;
          MainWindow.Size = new Size(1000, 700);
          MainWindow.KeyPreview = true;
          MainWindow.KeyPress = new KeyPressEventArgs(Form_KeyPress); 
  
          MainWindow.ShowDialog();
  
      }
  
      private void Form_KeyPress(object sender, System.Windows.Forms.KeyEventArgs e)
      {
          if(e.KeyCode == Keys.A){
              MessageBox.Show("You pressed the A key.");
          }
      }
  
  }
  </code></pre>