处理 ToolStripComboBox 中的 Tab 键

发布于 2024-09-02 16:42:43 字数 272 浏览 2 评论 0原文

我在 ToolStrip 中有一个 ToolStripComboBox,当我按其中的 TAB 键时,它会将焦点集中到下一个工具条按钮。我想改变这种行为,并将焦点放在表单上的富文本框上。

问题是 ToolStripComboBox 没有 PreviewKeyDown 事件。当在组合中按下 Tab 键时(仅当按下并且某些工具条按钮获得焦点时),不会调用托管 ToolStrip 工具栏的 PreviewKeyDown。

工具条工具栏的 TabStop 为 false。

有什么想法吗?

I have a ToolStripComboBox in a ToolStrip, and when I press TAB key in it, it gives focus to the next toolstrip button. I would like to change this behavior and give focus to a richtextbox on my form instead.

The problem is that ToolStripComboBox does not have PreviewKeyDown event. And PreviewKeyDown of the hosting ToolStrip Toolbar is not called when tab key is pressed in the combo (just when pressed and some toolstripbutton is focused).

TabStop of the toolstrip toolbar is false.

Any ideas?

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

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

发布评论

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

评论(1

凉风有信 2024-09-09 16:42:51

您可以在 ToolStrip 控件获取键之前在表单级别捕获此信息。重写表单的 ProcessCmdKey() 方法,使其看起来与此类似:

    protected override bool ProcessCmdKey(ref Message msg, Keys keyData) {
        if (keyData == Keys.Tab && this.ActiveControl == toolStripComboBox1.Control) {
            richTextBox1.Focus();
            return true;
        }
        return base.ProcessCmdKey(ref msg, keyData);
    }

You can catch this at the form level, before the ToolStrip control grabs the key. Override the form's ProcessCmdKey() method, make it look similar to this:

    protected override bool ProcessCmdKey(ref Message msg, Keys keyData) {
        if (keyData == Keys.Tab && this.ActiveControl == toolStripComboBox1.Control) {
            richTextBox1.Focus();
            return true;
        }
        return base.ProcessCmdKey(ref msg, keyData);
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文