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

Show image anchor positions using GDI+

This source code snippet requires TX Text Control .NET
Author:TX Text Control Support Department
Language:C#
Version:1.0
Released:April 25, 2007
Last modified:January 11, 2008
Requirements:TX Text Control .NET with .NET C#
Download code:tx_showanchorpositions.zip Download [10.54 KB, ZIP]
Click to enlarge

As of TX Text Control 12.0, images can be anchored to a paragraph. This mode allows end-users to insert an image with a geometrical position relative to a paragraph. Text flows around the image. If additional text is inserted in front of the parent paragraph, the image is moved with the text.

In documents, into which such images have been inserted, it is often necessary to know to which paragraph a specific image is anchored.

To visualize the parent position in a text, an anchor icon drawn onto TextControl using GDI+.

The TextPosition property of the Image class can be used in combination with the InputPosition class to retrieve the location at which the icon should be placed. Additionally, this sample displays the image filename and the image size in Pixel above the image.

The following code shows how to calculate the anchor position:

  1. g = textControl1.CreateGraphics();
  2.  
  3. Image anchorImage = Bitmap.FromStream(GetEmbeddedFile("tx_showanchorpositions.anchor.gif"));
  4. textControl1.InputPosition = new TXTextControl.InputPosition(curImage.TextPosition);
  5.  
  6. Point anchorPos = new Point((textControl1.InputPosition.Location.X _
  7. - textControl1.ScrollLocation.X - 400) / twipsPerPixel, _
  8. (textControl1.InputPosition.Location.Y - _
  9. textControl1.ScrollLocation.Y) / twipsPerPixel);
  10.  
  11. Point imagePos = new Point(anchorPos.X + (curImage.Location.X / twipsPerPixel) + 30 _
  12. , anchorPos.Y + (curImage.Location.Y / twipsPerPixel) - 15);
  13.  
  14. g.DrawImage(anchorImage, anchorPos);

The sample requires Visual Studio 2005 and at least a TX Text Control .NET 13.0 trial version.

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