TX Text Control Source Code Library

Setting the zoom factor using the mouse wheel

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 for Windows Forms 13.0 trial version and Visual Studio 2005.

Call us: +1 704-544-7445 (United States)





Buy Now

About Text Control

Founded in 1991, Text Control is an award-winning Visual Studio Industry Partner and leading vendor of word processing and reporting components for Microsoft development technologies. The products help thousands of developers add comprehensive word processing functionality to their applications. Text Control is 100% self-owned and independent of all investor decisions. Customers benefit from these years of experience, large user-base, and at the same time, appreciate developing with a mature, reliable product.

SD Times 100SD Times 100SD Times 100SD Times 100SD Times 100SD Times 100Visual Studio 2015 Launch PartnerVisual Studio 2013 Launch PartnerVisual Studio 2012 Launch PartnerVisual Studio Partner