以编程方式更改选项卡键问题-c#窗口应用程序

以编程方式更改选项卡键问题-c#窗口应用程序,c#,winforms,combobox,windows-applications,C#,Winforms,Combobox,Windows Applications,我已在windows窗体中将“ENTER”键设置为“TAB”键 下面是代码 protected override bool ProcessCmdKey(ref Message msg, Keys keyData) { KeyEventArgs e = new KeyEventArgs(keyData); if (e.KeyCode == Keys.Enter) { SendKeys.Send("{TAB}");

我已在windows窗体中将“ENTER”键设置为“TAB”键

下面是代码

protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
    {
        KeyEventArgs e = new KeyEventArgs(keyData);
        if (e.KeyCode == Keys.Enter)
        {
            SendKeys.Send("{TAB}");
        }
        if (e.KeyCode == Keys.Escape)
        {
            this.Close();
        }
        return base.ProcessCmdKey(ref msg, keyData);
    }
它与所有控件都能完美地工作,但当我在任何组合框上按ENTER键时,它会使用两个选项卡索引。 例如

  • 文本框1
  • 组合框
  • 文本框2
  • 文本框3
  • 文本框4
  • 当我按ENTER键离开组合框时,光标(焦点)直接进入文本框3 我想把焦点放在combobox的下一个控件上,即textbox 2

    请帮帮我

    提前谢谢

    属性决定按下Tab键时控件应聚焦的顺序

    您应该设置控件的
    TabIndex
    属性,设置的顺序应使控件基于Tab键的按下而聚焦


    也就是说,您不应该使用
    SendKeys.Send(“{TAB}”)
    方法来模拟TAB键按下。为此,您应该使用方法。

    只需
    返回true发送选项卡后:

        protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
        {
            KeyEventArgs e = new KeyEventArgs(keyData);
            if (e.KeyCode == Keys.Enter)
            {
                SendKeys.Send("{TAB}");
                return true;
            }
            if (e.KeyCode == Keys.Escape)
            {
                this.Close();
            }
            return base.ProcessCmdKey(ref msg, keyData);
        }
    

    谢谢您的回复,但您能否解释一下如何使用控件。选择下一个控件方法?我是这方面的新手。@Mr.Go您应该能够调用
    this。选择nextcontrol(cc.ActiveControl,true,true,true,true)未测试。看看这是否有效。或者看看类似的问题嘿,还是不行,伙计。在组合框上,它需要2个选项卡…:(您的控件(textbox2、textbox3等)中设置了哪些
    选项卡索引
    )?您是否检查了它们是什么?