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

Implementing guides for tabstops TX Text Control .NET

This source code snippet requires TX Text Control .NET
Author:TX Text Control Support Department
Language:C# .NET
Version:1.0
Released:March 29, 2006
Last modified:January 11, 2008
Requirements:TX Text Control .NET with C# .NET
Download code:tabstop_guide_sample.zip Download [22.8 KB, ZIP]
Click to enlarge

Tabstop guides are a useful feature that allow end users to format text. This sample application shows you how to implement guides for tabstops and inline indent markers in TX Text Control.

By using the CreateGraphics method of TX Text Control, the guides are created and shown when the user clicks on the RulerBar.

The guides are not only used for positioning tabstops, but also for the indent markers, so users can easily place tabstops or indents at the correct position.

To show a tabstop guide, the MouseDown event of the RulerBar is used and a line is drawn on TX Text Control.

  1. private void rulerBar1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
  2. {
  3. if (e.Button == MouseButtons.Left)
  4. {
  5. textControl1.CreateGraphics().DrawLine(Pens.DarkGray,_
  6. e.X, 0 , e.X, textControl1.Height);
  7. }
  8. }

After that, the MouseMove event will be used to capture the movement of the mouse and move the line accordingly.

  1. private void rulerBar1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
  2. {
  3. if (e.Button == MouseButtons.Left)
  4. {
  5. textControl1.Refresh();
  6. textControl1.CreateGraphics().DrawLine(Pens.DarkGray,_
  7. e.X, 0, e.X, textControl1.Height);
  8. }
  9. }

If the MouseUp event occurs, the tabstop or indent is automatically placed by the RulerBar at the current position and the TX Text Control's content needs to be refreshed.

  1. private void textControl1_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
  2. {
  3. if (e.Button == MouseButtons.Left)
  4. {
  5. textControl1.Refresh();
  6. }
  7. }

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

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