Disable CTRL + MOUSE WHEEL

The zoom factor in TXTextControl.TextControl TX Text Control .NET for Windows Forms
TXTextControl Namespace
TextControl Class
The TextControl class implements a Windows Forms control with high-level text editing features.
can be set using CTRL + MOUSE WHEEL. Disabling this built-in functionality is possible using a simple trick. The MouseWheel event event itself cannot be canceled. Therefore you have to cast its arguments to HandledMouseEventArgs event. Then, you can handle the event, when key events are fired. Simply use an isKeyDown flag in the KeyUp and KeyDown event.

//create isKeyDown flag
private bool _isKeyDown = false;
private void Form1_Load(object sender, EventArgs e) {
//subscribe to MouseWheel event
textControl1.MouseWheel += TextControl1_MouseWheel;
}
private void TextControl1_MouseWheel(object sender, MouseEventArgs e) {
//check if key has been pressed
if (_isKeyDown == true) {
//if yes handle the event
((HandledMouseEventArgs)e).Handled = true;
}
}
private void textControl1_KeyDown(object sender, KeyEventArgs e) {
//set flag to true when key is pressed
_isKeyDown = e.Control;
}
private void textControl1_KeyUp(object sender, KeyEventArgs e) {
//set flag to false when key has been released
_isKeyDown = e.Control;
}
view raw test.cs hosted with ❤ by GitHub

Zoom Using Keyboard Only

Since zooming via the CTRL + MOUSEWHEEL has now been disabled, zooming using the keyboard only, can be added easily. In the KeyDown event, check if CTRL + Plus has been pressed. If yes, simply increase the current zoom factor by ten. If CTRL + Minus has been pressed, decrease the current value by ten. Since the zoom factor cannot be less than ten, Math.Max method is used to ensure that the value is never less than ten. Now, users can zoom in and out by pressing and holding CTRL and Plus or Minus.

private void textControl1_KeyDown(object sender, KeyEventArgs e) {
//increase zoom by ten percent when pressing CTRL + Plus
int currZoom = textControl1.ZoomFactor;
if (e.Control && (e.KeyCode == Keys.Oemplus)) {
textControl1.Zoom(currZoom + 10);
}
//decrease zoom by ten percent when pressing CTRL + Minus
if (e.Control && (e.KeyCode == Keys.OemMinus)) {
textControl1.Zoom(Math.Max(10, currZoom - 10));
}
}
view raw test.cs hosted with ❤ by GitHub

Set Zoom Level to Default

To reset the zoom back to the default value, press and hold CTRL + 0. This can be implemented in the KeyDown event with this code:

private void textControl1_KeyDown(object sender, KeyEventArgs e) {
//reset the zoom back to the default (100%) when presing Ctrl + 0
if (e.Control && (e.KeyCode == Keys.NumPad0 || e.KeyCode == Keys.D0)) {
textControl1.Zoom(100);
}
}
view raw test.cs hosted with ❤ by GitHub