版权声明:本文为博主原创文章,转载请注明出处。 https://blog.csdn.net/sinat_27305053/article/details/79161757
1. this.ActiveControl = this.button2;
2. this.button2.Focus(); //
namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
//this.ActiveControl = this.button2;//生效
//this.button2.Focus();//不生效
}
private void Form1_Load(object sender, EventArgs e)
{
//this.ActiveControl = this.button2;//生效
//this.button2.Focus(); //不生效
}
private void Form1_Shown(object sender, EventArgs e)
{
//this.ActiveControl = this.button2;//生效
//this.button2.Focus(); //生效
}
private void Form1_Paint(object sender, PaintEventArgs e)
{
//this.ActiveControl = this.button2;//生效
this.button2.Focus(); //生效
}
}
}