How-To: 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);
Public Sub New(ByVal columns As Integer, columnWidths As Integer(), columnDistances As Integer())

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)
    TXTextControl.SectionFormat currentFormat =

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

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

    textControl1.Sections.GetItem().Format = newSectionFormat;
Private Sub InsertColumns(FirstColumnWidth As Integer, ColumnDistance As Integer)
    Dim currentFormat As TXTextControl.SectionFormat = textControl1.Sections.GetItem().Format
    Dim iSecondColumnWidth As Integer = CInt(Math.Truncate(
            (currentFormat.PageSize.Width * 14.4) -
            (currentFormat.PageMargins.Left * 14.4) -
            (currentFormat.PageMargins.Right * 14.4) -
            FirstColumnWidth -

            Dim newSectionFormat As New TXTextControl.SectionFormat(
            New Integer() {FirstColumnWidth, iSecondColumnWidth},
            New Integer() {ColumnDistance})

    textControl1.Sections.GetItem().Format = newSectionFormat
End Sub