title: Using an if statement to see if a button is clicked in Windows Forms C#
body: <p>I have a Windows Form application that is being used to practice the Bubble Sort algorithm.  Basically I have four different radio buttons which each displays a certain number of random integers in a listbox when clicked.  What I want is to be able to click a button that says "Sort" to then sort all the integers in that listbox.  Since each radio button displays different integers in the listbox, I have to do this under the radioButton1_CheckedChange method, so then I may have easy access to the random array that has been created for the listbox.  I am currently struggling with getting my code to make the button1_Clicked event handler to be set to "true" when the button is clicked.  Here's an excerpt of my code below to show you guys what I mean.</p>
  
  <pre><code>bool buttonClick = false;
      private void button1_Click(object sender, EventArgs e)//When button is clicked, button click is true
      {
          buttonClick = true;
      }
  
      private void radioButton1_CheckedChanged(object sender, EventArgs e)//Max 100 button
      {
          int smallMaxSize = 101;
          int[] array = new int[smallMaxSize];
  
          Random numGenerator = new Random();
  
          numGenerator.Next(smallMaxSize);
  
          for (int i=0; i&lt;101; i++)//Generates 100 random numbers from 1-100
          {
              array[i] = numGenerator.Next(smallMaxSize);
              Numbers.Items.Add(array[i]);
          }   
  
          if (buttonClick == true)
          {
              Numbers.Items.Clear();
              int Out;
              int In;
  
              for (Out = smallMaxSize - 1; Out &gt; 1; Out--)
              {
                  for (In = 0; In &lt; Out; In++)
                  {
                      if (array[In] &gt; array[In + 1])
                      {
                          int temp = array[In];
                          array[In] = array[In + 1];
                          array[In + 1] = temp;
                      }
                  }
              }
          }
  </code></pre>
  
  <p>As you can see, I've set up a private bool for the button click, which is always set to false.  Under the button1_Click event handler, I have that change to true whenever the "Sort" button is clicked.  Then I have an "if" statement under the Radio Button method that says "if buttonClick == true, run this code".  When I run the code and click the "Sort" Button, nothing happens.  Anyone have any ideas that could lead me in the right direction?</p>