-2

How can I set my text box "Fahrenheit" in focus when the program starts that I don't have to click it manually? Because the program has only 1 function and it would be more comfortable.

namespace Fahrenheit
{
  public partial class Form1 : Form
  {
    public Form1()
    {
      InitializeComponent();
    }

    private void label2_Click(object sender, EventArgs e)
    {
    }

    private void textBox1_TextChanged(object sender, EventArgs e)
    {
      this.ActiveControl = textBox1;

      double Fahrenheit = Convert.ToDouble(textBox1.Text);
      double Celsius = (Fahrenheit - 32) * 5.0 / 9.0;

      textBox2.Text = Celsius.ToString("F");
    }

    private void Form1_Load(object sender, EventArgs e)
    {

    }
  }
}
Salah Akbari
  • 39,330
  • 10
  • 79
  • 109
user5462581
  • 159
  • 1
  • 3
  • 13

1 Answers1

3

the line this.ActiveControl = textBox1; should be below the InitializeComponent(); Like this:

public Form1()
{
  InitializeComponent();
  this.ActiveControl = textBox1;
}
Salah Akbari
  • 39,330
  • 10
  • 79
  • 109