You will need to process KeyDownand KeyUpto determine if the key is held down Ctrl. This value must be stored at the class level, because it will be used by other routines other than KeyDownand KeyUp.
Then you write code to process the form MouseWheel. Scrolling down (towards you) causes a negative value for the Deltaproperty MouseEventArgs. Scrolling up is obviously the other way around. The value of the Delta property is always 120.
Microsoft's reason for this value is as follows:
A value of 120 is currently the standard for a single stopper. If higher resolution mice are introduced, the definition of WHEEL_DELTA may be reduced. Most applications should check for a positive or negative value, not a general population.
Delta .
, :
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 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
: