在VB.NET中使用鼠标滚轮和Ctrl控制WinForms的缩放级别
如果我有一个 winform,我可以知道如何使用 Ctrl + 鼠标滚轮控制应用程序中字体的缩放级别(显然还有应用程序窗口本身)?我看到滚轮事件中有一个 Delta,但不确定它是如何工作的。有没有我可以查看的代码示例?
If I have a winform, may I know how can I control the zoom level of the font in the application (as well as the application window itself obviously) by using Ctrl + Mouse Scroll Wheel? I see there is a Delta in the Scroll Wheel event, but not sure how that works. Is there any code sample that I can look into?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我怀疑你可以测试:
(VB.NET):(
C#):
来检查控制键是否按下。
I suspect that you can just test:
(VB.NET):
(C#):
to check if the control key is down.
您必须处理
KeyDown
和KeyUp
事件以确定 Ctrl 键是否为被压制。该值应该存储在类级别,因为除了KeyDown
和KeyUp
事件之外,其他子例程也会使用它。然后编写代码来处理表单的
MouseWheel
事件。向下滚动(朝您的方向)会导致MouseEventArgs
的Delta
属性。向上滚动显然是相反的。目前Delta属性的值始终是120。微软给出这个值的原因如下:
在您的上下文中,您只需检查 Delta 的符号并执行操作。
以下是实现基本“缩放”功能的示例代码:
请阅读以下内容以获取有关您的问题的更多信息:
You'll have to handle the
KeyDown
andKeyUp
event in order to determine whether or not Ctrl key is being held down. This value should be stored at class-level because it will be used by other subroutines besides theKeyDown
andKeyUp
events.You then write code to handle the form's
MouseWheel
event. Scrolling downwards (towards you) causes a negative value for theDelta
property of theMouseEventArgs
. Scrolling upwards is obviously the reverse. The value of the Delta property is always currently 120.Microsoft's reason for this value is as follows:
In your context you'll just check for the sign of the Delta and perform an action.
Here is a sample code implementing basic 'zoom' functionality:
Read on the following for more information about your question:
对于 CrystalReportViewer1
只需放入 CrystalReportViewer1.Zoom(ZoomValue)
而不是子缩放中的 Me.Text = ZoomValue.ToString() 行
For CrystalReportViewer1
Just put CrystalReportViewer1.Zoom(ZoomValue)
instead of the line Me.Text = ZoomValue.ToString() in the Sub Zoom