| Skype: | TextControlSupport | |
| Orders: | 877-462-4772 |

| Author: | TX Text Control Support Department |
| Language: | C# .NET |
| Version: | 1.0 |
| Released: | August 20, 2007 |
| Last modified: | January 11, 2008 |
| Requirements: | TX Text Control .NET with C# .NET |
| Download code: | tx_mouse_zoom.zip |
MS Word implements a features that allows users to utilize the mouse wheel to set the zoom factor. When the user presses the CTRL key and uses the scroll wheel, the zoom factor is increased or decreased.
Using the implemented MouseWheel event of TX Text Control, a delta value can be retrieved that indicates the number of detents the mouse wheel has rotated.
In the Form's load event, the MouseWheel event can be attached:
public Form1() { InitializeComponent(); textControl1.MouseWheel += new MouseEventHandler(textControl1_MouseWheel); }
In the event, the return value is divided by 20 which is a fairly good factor to increase or decrease the zoom factor. It is encapsulated in a try / catch environment to avoid checking the boundaries manually. A flag is used that indicates whether the CTRL key is pressed or not. This variable is set in the KeyDown and KeyUp events.
void textControl1_MouseWheel(object sender, MouseEventArgs e) { if (!CtrlFlag) return; try { textControl1.ZoomFactor -= (e.Delta / 20); } catch { } }
To ensure that the current input position is visible, the ScrollLocation is set after a potential scroll action:
private void textControl1_VScroll(object sender, EventArgs e) { if (CtrlFlag) { textControl1.ScrollLocation = textControl1.InputPosition.Location; } }
The minimum requirements for this sample application are TX Text Control .NET 13.0 trial version and Visual Studio 2005.