[英]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.