CF - 将焦点设置到特定控件

发布于 2024-09-05 05:58:28 字数 535 浏览 2 评论 0原文

我有一个表单,它有一个面板,其中有一些文本框和位于面板外部的复选框。 每次加载表单时,复选框都会获得焦点。

我在表单加载时放置了事件处理程序,并尝试将焦点设置在第一个文本框上,而不是将其放在复选框上。

this.Activated += new EventHandler(form_Activated);

在该方法中,我尝试将焦点设置在面板中的第一个文本框上,

        private void form_Activated(object sender, EventArgs e)
    {
        if (this.parametersPanel.Controls.Count > 0)
        {
            this.parametersPanel.Focus();
            (this.parametersPanel.Controls[0]).Focus();
        }
    } 

但这不起作用,some1 可以帮助我吗?

I have a Form that has a panel with some textBoxes and checkBox that is outside the panel.
Every time the Form is loaded the checkBox has focus.

I have put en event handler when form loads and tried to set focus on first textbox instead having it on the checkbox.

this.Activated += new EventHandler(form_Activated);

in the method i try to set the focus on the first textbox in the panel

        private void form_Activated(object sender, EventArgs e)
    {
        if (this.parametersPanel.Controls.Count > 0)
        {
            this.parametersPanel.Focus();
            (this.parametersPanel.Controls[0]).Focus();
        }
    } 

This does not work, can some1 help me pls?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

诗化ㄋ丶相逢 2024-09-12 05:58:28

尝试将焦点直接设置在文本框上,而不是使用面板的控件索引。

try setting the focus directly on the textbox instead of using panel's controls index.

分分钟 2024-09-12 05:58:28

在设计模式下,选择您的控件并将其 tabindex 设置为 0

In desing mode, select your control and set it's tabindex to 0

旧城空念 2024-09-12 05:58:28

选项 1:

将其放入表单的加载事件中:

this.ActiveControl = myTextBox;

选项 2:

将其放入表单的加载事件中:

this.Show();
myTextBox.Focus();

Focus() 在 TextBox 可见之前不会起作用。

Option 1:

Put this in the form's load event:

this.ActiveControl = myTextBox;

Option 2:

Put this in the form's load event:

this.Show();
myTextBox.Focus();

Focus() will not work until the TextBox is visible.

绳情 2024-09-12 05:58:28

尝试使用 Shown 代替 Activated

Instead of Activated try Shown

太阳男子 2024-09-12 05:58:28

Yoc可以使用Ahmet提供的解决方案。由于您希望文本框获得焦点...将选项卡索引设置为零即可做到这一点。

您还可以使用文本框的焦点方法在表单的加载事件中设置焦点......

Yoc can use the solution provided by Ahmet. Since you want the text box to have the focus...setting the tab index to zero will do that.

Also you can use the textbox'e focus method to set the focus, in the form's load event....

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文