Zoom Tricks: Disabling CTRL + MOUSE WHEEL and More
Additional to the built-in zooming features, more tricks can be implemented on top. Some users may wish to disable the existing behavior and customize the behavior according to their requirement. This article shows how to disable CTRL + MOUSE WHEEL, implement zooming with keyboard and reset the zoom factor to its default value.

Disable CTRL + MOUSE WHEEL
The zoom factor in TXText
//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;
}
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));
}
}
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);
}
}
Windows Forms
Text Control combines the power of a reporting tool and an easy-to-use WYSIWYG word processor - fully programmable and embeddable in your Windows Forms application. TX Text Control .NET for Windows Forms is a royalty-free, fully programmable rich edit control that offers developers a broad range of word processing features in a reusable component for Visual Studio.