how to put focus on TextBox when the form load?

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

    You could try:

    MyTextBox.Select();

    According to the documentation:

    The Select method activates the control if the control's Selectable style bit is set to true in ControlStyles, it is contained in another control, and all its parent controls are both visible and enabled.

    You can first check if the control can be selectable by inspecting the MyTextBox.CanSelect property.

提交回复
热议问题