C# - 将焦点传递给选项卡控件/页面并且无法滚动鼠标滚轮
我有一个组合框,其中有四个项目对应于选项卡控件中的选项卡。当用户从组合框中选择一个项目(通过左键单击并再次左键单击来选择一个项目)时,选项卡控件中相应的选项卡页将被选中。选项卡页设置为自动滚动,但是当以这种方式选择选项卡页时,鼠标滚轮滚动不起作用。 (如果我手动单击该选项卡内的控件,则可以使用鼠标滚轮滚动..)
如果用户使用鼠标滚轮从同一组合框中选择一个项目(并成功地将控制传递到相应的选项卡页),则鼠标滚轮滚动在该选项卡上工作正常,我不能找出原因。
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我无法重现这个问题。可能有帮助的方法是将焦点设置到页面的第一个控件,就像通过单击控件来修复问题时发生的情况一样。并在组合框事件完成后执行此操作。使用此方法:
在 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:
Call setFocusToPage instead of the Focus() method in your SelectedIndexChanged event handler.