Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/338.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在WinC窗体中加载用户控件时,将焦点放在文本框中_C#_Winforms_User Controls_Load - Fatal编程技术网

C# 在WinC窗体中加载用户控件时,将焦点放在文本框中

C# 在WinC窗体中加载用户控件时,将焦点放在文本框中,c#,winforms,user-controls,load,C#,Winforms,User Controls,Load,加载用户控件时如何设置文本框的焦点 在winforms中,我在usercontrol.load中编写了textbox1.focus,但它不起作用。试试。改为选择方法 textBox1.Select(); 或 或者,您可以尝试: private TextBox TextFocusedFirstLoop() { // Look through all the controls on this form. foreach (Control con in this.Controls)

加载用户控件时如何设置文本框的焦点


在winforms中,我在usercontrol.load中编写了textbox1.focus,但它不起作用。

试试。改为选择方法

textBox1.Select();

或者,您可以尝试:

private TextBox TextFocusedFirstLoop()
{
    // Look through all the controls on this form.
    foreach (Control con in this.Controls)
    {
    // Every control has a Focused property.
    if (con.Focused == true)
    {
        // Try to cast the control to a TextBox.
        TextBox textBox = con as TextBox;
        if (textBox != null)
        {
        return textBox; // We have a TextBox that has focus.
        }
    }
    }
    return null; // No suitable TextBox was found.
}

private void SolutionExampleLoop()
{
    TextBox textBox = TextFocusedFirstLoop();
    if (textBox != null)
    {
    // We have the focused TextBox.
    // ... We can modify or check parts of it.
    }
}

请尝试。改为选择方法

textBox1.Select();

或者,您可以尝试:

private TextBox TextFocusedFirstLoop()
{
    // Look through all the controls on this form.
    foreach (Control con in this.Controls)
    {
    // Every control has a Focused property.
    if (con.Focused == true)
    {
        // Try to cast the control to a TextBox.
        TextBox textBox = con as TextBox;
        if (textBox != null)
        {
        return textBox; // We have a TextBox that has focus.
        }
    }
    }
    return null; // No suitable TextBox was found.
}

private void SolutionExampleLoop()
{
    TextBox textBox = TextFocusedFirstLoop();
    if (textBox != null)
    {
    // We have the focused TextBox.
    // ... We can modify or check parts of it.
    }
}

小心你的账单!小心你的账单!