Products Technologies Demo Docs Blog Support Company

GetTextExtent with TX Text Control .NET for Windows Forms

The Lines collection in TX Text Control .NET for Windows Forms replaces the ActiveX GetTextExtent property for measuring document dimensions. TextBounds.Bottom on the last line returns total text height, while iterating all lines and comparing TextBounds.Right finds maximum width.

GetTextExtent with TX Text Control .NET for Windows Forms

TX Text Control ActiveX contains a property which returns the extension of the complete text in twips. This method is not directly supported in the .NET version of TX Text Control. The Lines collection has been implemented to replace this method and includes lots of additional functionality.

The TextBounds property of the Line class gets the bounding rectangle of the text belonging to the line. We need the vertical distance between the upper left corner and the baseline of the last line to get the height of the complete text. Additionally, we need the longest line of the current document. This is done by checking the longest line in a loop.

Dim TextHeight As Long
Dim TextWidth As Long

TextHeight = TextControl1.Lines.Item(TextControl1.Lines.Count).TextBounds.Bottom

For Each line As TXTextControl.Line In TextControl1.Lines
    Dim lineWidth As Long = TextControl1.Lines.Item(line.Number).TextBounds.Right

    If TextWidth < lineWidth Then
        TextWidth = lineWidth
    End If
Next

Debug.WriteLine(TextHeight)
Debug.WriteLine(TextWidth)

Stay in the loop!

Subscribe to the newsletter to receive the latest updates.

Related Posts

Windows FormsWPF.NET

Create a Table of Contents in Windows Forms using C#

This article explains how to create a table of contents in Windows Forms using the ribbon or programmatically. Creating a table of contents is required to organize large documents.


Windows FormsList.NET

Two Ways to Restart Numbered Lists in TX Text Control

In TX Text Control, numbered lists are continued by default and need to be reset when required. There is more than one way if you want to restart numbered lists in a document. In this article, two…


.NETSample

Paste Special: The Easy Way to Implement

TX Text Control version 15.0 introduced a ClipboardFormat parameter on the Paste method, enabling native Paste Special functionality. The GetClipboardFormats method returns all available clipboard…


.NETSampleSections

How to Remove All Section Breaks in a Document?

TX Text Control 15.0 adds per-section page column support alongside existing section breaks. To remove all section breaks programmatically, iterate through SectionCollection using…


.NETPrintingSample

Batch Printing: How to Print Documents in One Print Job

Batch printing multiple documents as a single print job using TX Text Control relies on a .NET PrintDocument with PrintPage and QueryPageSettings events. Each page is rendered individually via the…

Share on this blog post on: