I have received several inquiries on how to programatically insert a page break using TX Text Control .NET for Windows Forms. Generally, this is quite simple: Just insert the control character for a page break using the Selection.Text property:

C#:

textControl1.Selection.Text = "\f";

VB .NET:

TextControl1.Selection.Text = Chr(12)

If you insert a page break using the key combination CTRL + ENTER, TX Text Control scrolls automatically to this new input position. TX Text Control won't scroll automatically, if you insert a page break by code as this might be not the intention of the developer.

To scroll to the new input position, the ScrollLocation property can be used:

C#:

private void InsertPageBreak()
{
    textControl1.Selection.Text = "\f";
    System.Drawing.Point ScrollPosition = new Point(0, textControl1.InputPosition.Location.Y);
    textControl1.ScrollLocation = ScrollPosition;
    textControl1.Focus();
}

VB .NET:

Private Sub InsertPageBreak()
    TextControl1.Selection.Text = Chr(12)
    Dim ScrollPosition As New System.Drawing.Point(0, TextControl1.InputPosition.Location.Y)
    TextControl1.ScrollLocation = ScrollPosition
    TextControl1.Focus()
End Sub