how to put focus on TextBox when the form load?

前端 未结 16 1100
清歌不尽
清歌不尽 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:18

    use form shown event and set

    MyTextBox.Focus();
    
    0 讨论(0)
  • 2020-12-04 15:18

    In jquery set focus

    $(function() {
      $("#txtBox1").focus();
    });
    

    or in Javascript you can do

    window.onload = function() {
      document.getElementById("txtBox1").focus();
    };
    
    0 讨论(0)
  • 2020-12-04 15:19

    check your tab order and make sure the textbox is set to zero

    0 讨论(0)
  • 2020-12-04 15:19

    You can use either textBox1.select(); or the TabIndex in textbox setting. TabIndex=0 focoused first.

    0 讨论(0)
  • 2020-12-04 15:24

    Set Tab Index property's value = 0 and then in form load function write :

    YourTextboxName.Focus();
    

    It will work.

    0 讨论(0)
  • 2020-12-04 15:24

    Set Tabstop to True and TabIndex to the minimum to the control on which you need focus.

    e.g. If you have 2 TextBoxes : TextBox1 and TextBox2, set Tabstop to True for both and TabIndex to 0 and 1 respectively. When the form loads, the focus will be on TextBox1 and on the press of 'Tab' key, the focus will move to TextBox2.

    0 讨论(0)
提交回复
热议问题