简体   繁体   English

我如何才能使MouseWheel正常工作而不必先集中精力于表单?

[英]How can I make MouseWheel work without first having to focus the form?

I have a form with only a ReportViewer control on it. 我有一个只带有ReportViewer控件的表单。 When the form is displayed, if you click on the report you can then use the mouse wheel to scroll vertically. 显示表单时,如果单击报表,则可以使用鼠标滚轮垂直滚动。

I'd like to be able to scroll as soon as the form appears. 我希望能够在表单出现后立即滚动。

I've tried the following, but no dice... 我尝试了以下方法,但没有骰子...

    private void ReportViewer_Load(object sender, EventArgs e)
    {
        rptViewer.Focus();
    }

    private void ReportViewer_Activated(object sender, EventArgs e)
    {
        rptViewer.Focus();
    }

Put your code in the form's constructor, right after InitializeComponent(); 将代码放在InitializeComponent();之后的窗体的构造函数中InitializeComponent(); :

rptViewer.Select();

Did you try calling rptView.Activate()? 您是否尝试调用rptView.Activate()?

Also it may be that your form is getting focus after the load event completes (I think I've had problems with that before). 也有可能是您的表单在load事件完成之后就变得集中了(我想我以前对此有问题)。 One solution is, although it is definitely not elegant, to create a single-use Timer that starts when your Load method runs, and fires after 1 ms, and then stops. 一种解决方案是创建一个一次性计时器,尽管它绝对不是很优雅,但它会在您的Load方法运行时启动,并在1毫秒后触发,然后停止。 When the Timer fires, it will activate/focus your ReportViewer. 当计时器触发时,它将激活/聚焦您的ReportViewer。

You could also try adding a MouseWheel event handler to your form. 您也可以尝试将MouseWheel事件处理程序添加到表单中。 When the event is fired, send a scroll message to your ReportViewer to scroll it up or down. 触发事件后,向您的ReportViewer发送滚动消息以向上或向下滚动。 Then it doesn't matter whether or not your ReportViewer has focus, it (should) always scroll when the form has focus. 然后,不管您的ReportViewer是否具有焦点,它都应该在表单具有焦点时始终滚动。

设置rptViewer.Focus调用SendKeys.Send(Chr(Keys.Tab))将焦点从菜单移动到预览区域。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在设计时使自定义控件的单击激活而又没有首先获得焦点? - How can I make have a custom control's click activate during design time without it first having focus? 如何在不让用户首先关注文本框的情况下阅读条形码? - How can I read barcodes without having the user focus a text box first? 如何使MouseWheel在滚动条上工作 - How to make MouseWheel work on the scrollbar 如何使Windows 8 Metro scrollviewer响应鼠标滚轮? - How can I make a Windows 8 Metro scrollviewer respond to mousewheel? 如何制作一个可预滚动的标签控件,以便我可以添加大量文本框而无需占用整个屏幕的窗体 - how to make a prescrollable tab control so i can add in tons of text boxes without having the form not take up the entire screen winforms应用程序如何在没有焦点的情况下接受用户输入? - How can a winforms application accept user input without having focus? 如何在不给予焦点的情况下将所有表单的“拥有的表单”强制显示在最前面? - How can I force all of a form's 'owned forms' to the front without giving them the focus? 如何在AvalonDock中使WinForms Form作为DockableContent工作? - How can I make a WinForms Form work as a DockableContent in AvalonDock? 如何在没有单击事件的情况下使TabContem专注于TabControl? - How can I make a specific TabItem gain focus on a TabControl without click event? 如何打开 Word 文档而不必先将其保存在服务器上? - How can I open Word document without having to save it first on the Server?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM