Results 1 to 3 of 3

Thread: [RESOLVED] RichTextBox - disable mouse scaling

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2009
    Posts
    629

    Resolved [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:
    Code:
    Me.ZoomFactor = 1
    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.

  2. #2
    PowerPoster boops boops's Avatar
    Join Date
    Nov 2008
    Location
    Holland/France
    Posts
    3,201

    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

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2009
    Posts
    629

    Re: RichTextBox - disable mouse scaling

    Thanks it works, although I changed it a bit around.

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width