[如果我有winform,我是否知道如何使用Ctrl +鼠标滚轮来控制应用程序中字体的缩放级别(显然还有应用程序窗口本身)?我看到“滚轮”事件中有一个Delta,但不确定如何运行。我可以查看任何代码示例吗?
您必须处理KeyDown
和KeyDown
事件,以确定是否按住Ctrl键。此值应存储在类级别,因为它会被KeyUp
和KeyUp
事件以外的其他子例程使用。
然后您编写代码来处理表单的KeyDown
事件。向下(向您)滚动会导致KeyUp
的MouseWheel
属性为负值。向上滚动显然是相反的。当前Delta属性的值始终为120。
Microsoft使用此值的原因如下:
当前,一个制动器的标准值为120。如果引入了更高分辨率的鼠标,则WHEEL_DELTA的定义可能会变小。大多数应用程序应检查正值或负值,而不是总计。
根据您的情况,您只需检查Delta的符号并执行操作。
这里是实现基本“缩放”功能的示例代码:
MouseWheel
请阅读以下内容,以获取有关您的问题的更多信息:
Delta
Delta
MouseEventArgs
Public Class Form1
Enum ZoomDirection
None
Up
Down
End Enum
Dim CtrlIsDown As Boolean
Dim ZoomValue As Integer
Sub New()
' This call is required by the designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
ZoomValue = 100
End Sub
Private Sub Form1_KeyDown_KeyUp(ByVal sender As Object, _
ByVal e As KeyEventArgs) _
Handles Me.KeyDown, Me.KeyUp
CtrlIsDown = e.Control
End Sub
Private Sub Form1_MouseWheel(ByVal sender As Object,
ByVal e As MouseEventArgs) _
Handles Me.MouseWheel
'check if control is being held down
If CtrlIsDown Then
'evaluate the delta's sign and call the appropriate zoom command
Select Case Math.Sign(e.Delta)
Case Is < 0
Zoom(ZoomDirection.Down)
Case Is > 0
Zoom(ZoomDirection.Up)
Case Else
Zoom(ZoomDirection.None)
End Select
End If
End Sub
Private Sub Zoom(ByVal direction As ZoomDirection)
'change the zoom value based on the direction passed
Select Case direction
Case ZoomDirection.Up
ZoomValue += 1
Case ZoomDirection.Down
ZoomValue -= 1
Case Else
'do nothing
End Select
Me.Text = ZoomValue.ToString()
End Sub
End Class
我怀疑您可以测试:
对于CrystalReportViewer1