how to put focus on TextBox when the form load?

前端 未结 16 1217
清歌不尽
清歌不尽 2020-12-04 14:59

I have in my C# program textBox

I need that when the program start, the focus will be on the textBox

I try this on Form_Load:

MyTextBox.Focus         


        
16条回答
  •  余生分开走
    2020-12-04 15:27

    Finally i found the problem i was using metro framework and all your solutions will not work with metroTextBox, and all your solutions will work with normal textBox in load , show , visibility_change ,events, even the tab index = 0 is valid.

       // private void Form1_VisibleChanged(object sender, EventArgs e)
       // private void Form1__Shown(object sender, EventArgs e)
        private void Form1_Load(object sender, EventArgs e)
        {
    
            textBox1.Select();
            this.ActiveControl=textBox1;
            textBox1.Focus();
        }
    

提交回复
热议问题