title: C# set focus on textbox
body: <p>I'm trying to set the "txtMiles" textbox to focus after:</p>
  
  <ol>
  <li>The form opens</li>
  <li>When the "clear" button is clicked</li>
  </ol>
  
  <p>I have tried using <code>txtMiles.Focus();</code> but it doesn't seem to work for me.</p>
  
  <p><strong><em>CODE BEING USED ON THIS FORM</em></strong></p>
  
  <pre><code>        private void btnConvert_Click(object sender, EventArgs e)
          {
              //assigns variable in memory.
              double txtMile = 0;
              double Results;
  
              try
              {
                  // here is where the math happens.
                  txtMile = double.Parse(txtMiles.Text);
                  Results = txtMile * CONVERSION;
                  lblResults.Text = Results.ToString("n2");
                  txtMiles.Focus();
              }
                  // if the user enters an incorrect value this test will alert them of such.
              catch
              {
                  //MessageBox.Show (ex.ToString());
                  MessageBox.Show("You entered an incorrect value");
                  txtMiles.Focus();
              }
          }
  
          private void btnClear_Click(object sender, EventArgs e)
          {
              //This empties all the fields on the form.
              txtMiles.Text = "";
              txtMiles.Focus();
              lblResults.Text = "";
          }
  
          private void btnExit_Click(object sender, EventArgs e)
          {
             // closes program
              this.Close();
          }
      }
  }
  </code></pre>
  
  <hr/>
  
  <p>Thanks in advance for the help.  </p>