程序启动时文本框处于焦点状态
Text box in focus when program starts
如何在程序启动时将我的文本框 "Fahrenheit" 设置为焦点,而不必手动单击它?因为程序只有1个功能,会比较舒服
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)
{
}
}
}
行 this.ActiveControl = textBox1;
应该在 InitializeComponent();
下方,像这样:
public Form1()
{
InitializeComponent();
this.ActiveControl = textBox1;
}
如何在程序启动时将我的文本框 "Fahrenheit" 设置为焦点,而不必手动单击它?因为程序只有1个功能,会比较舒服
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)
{
}
}
}
行 this.ActiveControl = textBox1;
应该在 InitializeComponent();
下方,像这样:
public Form1()
{
InitializeComponent();
this.ActiveControl = textBox1;
}