C# - 将焦点传递给选项卡控件/页面并且无法滚动鼠标滚轮

发布于 2024-10-09 15:58:45 字数 513 浏览 0 评论 0原文

我有一个组合框,其中有四个项目对应于选项卡控件中的选项卡。当用户从组合框中选择一个项目(通过左键单击并再次左键单击来选择一个项目)时,选项卡控件中相应的选项卡页将被选中。选项卡页设置为自动滚动,但是当以这种方式选择选项卡页时,鼠标滚轮滚动不起作用。 (如果我手动单击该选项卡内的控件,则可以使用鼠标滚轮滚动..)

如果用户使用鼠标滚轮从同一组合框中选择一个项目(并成功地将控制传递到相应的选项卡页),则鼠标滚轮滚动在该选项卡上工作正常,我不能找出原因。

private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
    switch (comboBox1.SelectedIndex)
    {
        case 0:
            tabControl1.SelectedTab = tabPage3;
            tabPage3.Focus();
            break;
    }
    ...
}

I have a combobox with four items that correspond to tabs in a tabcontrol. When the user selects an item from the combobox (by left clicking and left clicking again to select an item) the corresponding tabpage in the tabcontrol is selected. The tabpage is set to autoscroll but when the tabpage is selected in this way mousewheel scrolling does not work. (If I click a control inside that tabpage manually I can then mousewheel scroll..)

If the user mousewheels to select an item from the same combobox (and successfully passes control to the corresponding tabpage) mousewheel scrolling works fine on that tabpage and I cant figure out why.

private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
    switch (comboBox1.SelectedIndex)
    {
        case 0:
            tabControl1.SelectedTab = tabPage3;
            tabPage3.Focus();
            break;
    }
    ...
}

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

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

发布评论

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

评论(1

童话里做英雄 2024-10-16 15:58:45

我无法重现这个问题。可能有帮助的方法是将焦点设置到页面的第一个控件,就像通过单击控件来修复问题时发生的情况一样。并在组合框事件完成后执行此操作。使用此方法:

    private void setFocusToPage(TabPage page) {
        var ctl = page.Controls.Count > 0 ? page.Controls[0] : page;
        this.BeginInvoke((MethodInvoker)delegate { ctl.Focus(); });
    }

在 SelectedIndexChanged 事件处理程序中调用 setFocusToPage 而不是 Focus() 方法。

I can't get a repro of this problem. Something that might help is to set the focus to the first control of the page instead, just like what happens when you fix the problem by clicking a control. And to do so later, after the combobox event is completed. Use this:

    private void setFocusToPage(TabPage page) {
        var ctl = page.Controls.Count > 0 ? page.Controls[0] : page;
        this.BeginInvoke((MethodInvoker)delegate { ctl.Focus(); });
    }

Call setFocusToPage instead of the Focus() method in your SelectedIndexChanged event handler.

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