title: How To Check when a CheckBox is Checked In An IF statement And then perform an action in C#
body: <p>I have a question about how to check if a checkbox is checked programmatically in C# I'm currently busy with writing an operating system for spacecrafts in C# for crew members and passengers, it's not the meaning to publish it but I built it for testing with a complex network of resources and devices and maybe in the future an OS for spacecrafts but not now.</p>
  
  <p>The plan is to check if a checkbox is checked so the right crew-member gets the right access to the speech recognition engine and gets the permission to log-on to the right form!</p>
  
  <p>I have done this by writing this code:</p>
  
  <pre><code>using System;
  using System.Data;
  using System.Drawing;
  using System.Windows.Forms;
  using System.Data.SqlClient;
  using System.Speech.Recognition;
  using System.Speech.Synthesis;
  using System.IO;
  
  namespace HyperPod_OS
  {
      public partial class Login_Form : Form
      {
  
          // SETS THE INTS FOR THE AUTO TEXTBOX //
  
          private int a = 0;
          private int b = 0;
          private int c = 0;
          private int d = 0;
          private int f = 0;
          private int g = 0;
          private int h = 0;
          private int i = 0;
          private int j = 0;
          private int k = 0;
          private int l = 0;
          private int m = 0;
  
          // SPEECH ENGINE AND SYNTHESIZER //
  
          SpeechSynthesizer HelpAssistant = new SpeechSynthesizer();
  
          SpeechRecognitionEngine ReconEngine_Programmer = new     SpeechRecognitionEngine();
  
          SpeechRecognitionEngine ReconEngine_Data_Specialist = new SpeechRecognitionEngine();
  
          SpeechRecognitionEngine ReconEngine_Communication_Specialist = new SpeechRecognitionEngine();
  
          SpeechRecognitionEngine ReconEngine_System_Manager = new SpeechRecognitionEngine();
  
          SpeechRecognitionEngine ReconEngine_Captain = new SpeechRecognitionEngine();
  
          SpeechRecognitionEngine ReconEngine_Doctor = new SpeechRecognitionEngine();
  
          // LOADS THE FORM2 FOR BLENDING //
  
         Login_Form_Empty loginformempty;
  
         public Login_Form()
         {
  
              InitializeComponent();
  
              // LOADS THE GRAMMAR OBJECT FOR ALL CREW CLASSES //
  
                  ReconEngine_Programmer.SpeechRecognized += new         EventHandler&lt;SpeechRecognizedEventArgs&gt;(ReconEngine_Programmer_SpeechRecognized);
                  LoadGrammar_Programmer();
                  ReconEngine_Programmer.SetInputToDefaultAudioDevice();
  
                  ReconEngine_Data_Specialist.SpeechRecognized += new    EventHandler&lt;SpeechRecognizedEventArgs&gt;(ReconEngine_Data_Specialist_SpeechRecognized);
                  LoadGrammar_Data_Specialist();
                  ReconEngine_Data_Specialist.SetInputToDefaultAudioDevice();
  
                  ReconEngine_Communication_Specialist.SpeechRecognized += new  EventHandler&lt;SpeechRecognizedEventArgs&gt;(ReconEngine_Communication_Specialist_SpeechRecognized);
                  LoadGrammar_Communication_Specialist();
        ReconEngine_Communication_Specialist.SetInputToDefaultAudioDevice();
  
          ReconEngine_System_Manager.SpeechRecognized += new EventHandler&lt;SpeechRecognizedEventArgs&gt;(ReconEngine_System_Manager_SpeechRecognized);
          LoadGrammar_System_Manager();
          ReconEngine_System_Manager.SetInputToDefaultAudioDevice();
  
          ReconEngine_Captain.SpeechRecognized += new EventHandler&lt;SpeechRecognizedEventArgs&gt;(ReconEngine_Captain_SpeechRecognized);
          LoadGrammar_Captain();
          ReconEngine_Captain.SetInputToDefaultAudioDevice();
  
          ReconEngine_Doctor.SpeechRecognized += new EventHandler&lt;SpeechRecognizedEventArgs&gt;(ReconEngine_Doctor_SpeechRecognized);
          LoadGrammar_Doctor();
          ReconEngine_Doctor.SetInputToDefaultAudioDevice();
  
          // SETS THE SCREEN TO SEMI-TRANSPARENT //
  
          this.BackColor = Color.FromArgb(0, 190, 255);
          this.TransparencyKey = Color.FromArgb(0, 190, 255);
          this.StartPosition = FormStartPosition.Manual;
  
          // OPENS FORM4 AND SETS THE POSITION OF IT //
  
          loginformempty = new Login_Form_Empty();
          loginformempty.StartPosition = FormStartPosition.Manual;
          loginformempty.Location = new Point(200, 200);
          loginformempty.Show();
  
          // SETS THE METHOD OBJECTS // 
  
          this.LocationChanged += new EventHandler(Login_Form_LocationChanged);
          this.SizeChanged += new EventHandler(Login_Form_SizeChanged);
          this.FormClosed += new FormClosedEventHandler(Login_Form_FormClosed);
  
          // LOADS THE SPEECH ENGINE ON CHECKBOX //
  
          if (checkBox1.Checked == true)
          {
  
              ReconEngine_Programmer.RecognizeAsync(RecognizeMode.Multiple);
  
          }
  
          if (checkBox2.Checked == true)
          {
  
              ReconEngine_Data_Specialist.RecognizeAsync(RecognizeMode.Multiple);
  
          }
  
          if (checkBox3.Checked == true)
          {
  
                  ReconEngine_Communication_Specialist.RecognizeAsync(RecognizeMode.Multiple);
  
          }
  
          if (checkBox4.Checked == true)
          {
  
              ReconEngine_System_Manager.RecognizeAsync(RecognizeMode.Multiple);
  
          }
  
          if (checkBox5.Checked == true)
          {
  
              ReconEngine_Captain.RecognizeAsync(RecognizeMode.Multiple);
  
          }
  
          if (checkBox6.Checked == true)
          {
  
              ReconEngine_Doctor.RecognizeAsync(RecognizeMode.Multiple);
  
          }
      }
  </code></pre>
  
  <p>It doesn't work and I don't understand why.</p>