设置控件焦点

版权声明:本文为博主原创文章,转载请注明出处。 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(); //生效
        }
    }
}


猜你喜欢

转载自blog.csdn.net/sinat_27305053/article/details/79161757
今日推荐