Skype:TextControlSupport
Orders:877-462-4772
TX Text Control - word processing components.
What is this?Syndicate this content

Setting the zoom factor using the mouse wheel

This source code snippet requires TX Text Control .NET
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 Download [13.81 KB, 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:

  1. public Form1()
  2. {
  3. InitializeComponent();
  4. textControl1.MouseWheel += new MouseEventHandler(textControl1_MouseWheel);
  5. }

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.

  1. void textControl1_MouseWheel(object sender, MouseEventArgs e)
  2. {
  3. if (!CtrlFlag) return;
  4. try
  5. {
  6. textControl1.ZoomFactor -= (e.Delta / 20);
  7. }
  8. catch { }
  9. }

To ensure that the current input position is visible, the ScrollLocation is set after a potential scroll action:

  1. private void textControl1_VScroll(object sender, EventArgs e)
  2. {
  3. if (CtrlFlag)
  4. {
  5. textControl1.ScrollLocation = textControl1.InputPosition.Location;
  6. }
  7. }

The minimum requirements for this sample application are TX Text Control .NET 13.0 trial version and Visual Studio 2005.

top

Top 10 Bestselling Product Award 2007Top 25 Publisher Product Award 2007Top 10 Bestselling Product Award 2007 in JapanTop 25 Bestselling Product Award 2006Top 25 Bestselling Publisher Award 2006Reader's Choice Award, dot.net magazin, 3rd place