Products Technologies Demo Docs Blog Support Company

Inserting Columns Programmatically Using TX Text Control .NET

Generally, inserting page columns is a very easy task. Using the SectionFormat.Columns property, you can define the number of columns. TX Text Control will then automatically adjust the width of the columns based on the page size and number of columns. But if the columns should have a different size and should not be averaged and spread out on the page, we need to set the width of each column. This can be done in the SectionFormat constructor: public SectionFormat(int columns, int[]…

Inserting Columns Programmatically Using TX Text Control .NET

Generally, inserting page columns is a very easy task. Using the SectionFormat.Columns property, you can define the number of columns. TX Text Control will then automatically adjust the width of the columns based on the page size and number of columns.

But if the columns should have a different size and should not be averaged and spread out on the page, we need to set the width of each column. This can be done in the SectionFormat constructor:

public SectionFormat(int columns, int[] columnWidths, int[] columnDistances);

The second column width is calculated based on the first width, the distance between the columns, the page size and margins. This formula shows the calculation:

SecondColumnWidth = PageSize - PageMargins - FirstColumnWidth - ColumnDistance

The following code shows how to insert a new section with two columns where you just need to pass the first column width:

private void InsertColumns(int FirstColumnWidth, int ColumnDistance)
{
    textControl1.Sections.Add(TXTextControl.SectionBreakKind.BeginAtNewLine);
    TXTextControl.SectionFormat currentFormat =
        textControl1.Sections.GetItem().Format;

    int iSecondColumnWidth = (int)(
        (currentFormat.PageSize.Width * 14.4) -
        (currentFormat.PageMargins.Left * 14.4) -
        (currentFormat.PageMargins.Right * 14.4) -
        FirstColumnWidth -
        ColumnDistance
        );

    TXTextControl.SectionFormat newSectionFormat =
        new TXTextControl.SectionFormat(
            2,
            new int[] { FirstColumnWidth, iSecondColumnWidth },
            new int[] { ColumnDistance });

    textControl1.Sections.GetItem().Format = newSectionFormat;
}

The following illustration gives an overview of the different required variables for our calculation:

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.


ASP.NETWindows FormsWPF

Official TX Text Control .NET Sample Applications Are Now Hosted on GitHub

This article gives a quick overview of the new repositories, their structure and our plans for the future.


ASP.NETJavaScriptDocument Editor

Detect Toggle Button Changes Using a MutationObserver

This article shows how to detect changes of toggle buttons in the ribbon of the web editor using a MutationObserver. The state of a toggle button in the ribbon visualizes the state of a certain…


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…


Windows FormsSampleShortcuts

Zoom Tricks: Disabling CTRL + MOUSE WHEEL and More

This article shows how to disable CTRL + MOUSE WHEEL, implement zooming with keyboard and reset the zoom factor to its default value.