Disable RichTextBox zooming while scrolling with ctrl key

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



Disable RichTextBox zooming while scrolling with ctrl key



I am using RichTextBox in my c# application, I want to disable RichTextBox zooming while scrolling cursor with ctrl key, How to disable this? Please help.





Please provide your current research
– Matěj Štágl
Aug 6 at 7:32




2 Answers
2



You could override the WndProc of a custom RichTextBox control and filter the WM_MOUSEWHEEL Message. Then re-define the wParam content value (this value reports which combination of mouse buttons are pressed at that time), setting it to 0 (IntPtr.Zero).


RichTextBox


WM_MOUSEWHEEL


wParam


0


IntPtr.Zero



Then, let know that you processed this message, returning a m.Result of 0 (IntPtr.Zero).

(See the Docs on the WM_MOUSEWHEEL message about this).


m.Result


0


IntPtr.Zero


WM_MOUSEWHEEL



To test it, create a new Class and substitute its content with this code (except the Namespace). Build the Solution/Project. Find the RTBNoZoom control in your ToolBox and drop it on a Form.


Namespace


RTBNoZoom


using System;
using System.Windows.Forms;

public class RTBNoZoom : RichTextBox

private const int MK_CONTROL = 0x0008;
private const int WM_MOUSEWHEEL = 0x020A;

public RTBNoZoom()

protected override void WndProc(ref Message m)

switch (m.Msg)

case WM_MOUSEWHEEL:
if (((int)m.WParam & MK_CONTROL) == MK_CONTROL)

m.WParam = IntPtr.Zero;
m.Result = IntPtr.Zero;

break;
default:
break;

base.WndProc(ref m);




You can use the MOUSEWHEEL command and control.modifiers properties to control the zooming of your application.


protected override void DefWndProc(ref Message m)

if (m.Msg == WM_MOUSEWHEEL && Control.ModifierKeys == Keys.Control)

// Do what you want here

else

base.DefWndProc(ref m);







By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

Creating a leaderboard in HTML/JS