选中该文本框,右击属性,里的tabIndex设为0,焦点就默认在这个文本框里了。
Formload里面添加:
比如编辑框的名字:textBox_password
this.BeginInvoke((MethodInvoker)delegate { textBox_password.Focus(); });
private void button_Search_Click(object sender, EventArgs e) { string str1; // strDate= dateTimePicker1.ToString("yyyyMMdd"); str1 = dateTimePicker1.Value.ToString("yyyyMMdd"); str1 += ".txt"; textBox1.Text = ""; try { string[] ReadData = File.ReadAllLines(Application.StartupPath + "\\" + str1, Encoding.UTF8); // textBox1.Text = ReadData[0]; for (int i = 0; i < ReadData.Length; i++) { textBox1.Text += ReadData[i]; textBox1.Text += "\r\n"; } // textBox1.Select(0, 0);//光标停留的位置 // textBox1.Focus();//可以显示光标 // textBox1.SelectionStart = textBox1.Text.Length; textBox1.Select(textBox1.Text.Length, 0);//光标停留在最后末尾 } catch (Exception ex) { MessageBox.Show("所选日期无报警记录"); } }