这个问题在这里已有答案:
如何在程序启动时将我的文本框“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;
}