[RESOLVED] RichTextBox - disable mouse scaling
Hello everyone.
Finishing off my control, but I now found a nasty problem. When the user holds the 'Ctrl' key and scrolls the mouse scrollwheel, the control is scaled. I do not want that, since it would make the Font size fail.
I previously made it reset the scale on Control up, but that is just not a very elegant way:
I do not want the text scaled at any time, not even while the user is scrolling and it resets afterwards.
I got to overriding the 'ProcessCmdKey' but no idea how to catch a scroll or zoom event.
Any way of disabling the RichTextBox scaling (or zooming) so it does not even occur? I have a control that inherits from the RichTextBox. :)
Re: RichTextBox - disable mouse scaling
Here's how:
Code:
Public Class RTBnoZoom
Inherits RichTextBox
Private ctrlPressed As Boolean
Private Const WM_MOUSEWHEEL As Integer = &H20A
Public Sub New()
Me.SetStyle(ControlStyles.EnableNotifyMessage, True)
End Sub
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
If Not (m.Msg = WM_MOUSEWHEEL AndAlso ctrlPressed) Then MyBase.WndProc(m)
End Sub
Protected Overrides Sub OnKeyDown(e As System.Windows.Forms.KeyEventArgs)
If e.Modifiers = Keys.Control Then ctrlPressed = True
MyBase.OnKeyDown(e)
End Sub
Protected Overrides Sub OnKeyUp(e As System.Windows.Forms.KeyEventArgs)
ctrlPressed = False
MyBase.OnKeyUp(e)
End Sub
End Class
BB
Re: RichTextBox - disable mouse scaling
Thanks it works, although I changed it a bit around. :bigyello:
Code:
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
If m.Msg = WM_MOUSEWHEEL Then
Dim low As Short = m.WParam.ToInt32 - (m.WParam.ToInt32 >> 16) * 2 ^ 16
If (low And &H8) = &H8 Then Return
End If
MyBase.WndProc(m)
End Sub