Moving to a Page, Line or Column

TX Text Control's InputPosition class informs you about which page, line and column the current input position is at. It can also be used to move the input position to a different location.

The following example shows how to create a Goto Page function. An instance of the InputPosition class is created and initialized with a previously entered page number. The new input position is then assigned to the TextControl.InputPosition property.

[C#]
frmGotoPage GotoPage = new frmGotoPage();
GotoPage.ShowDialog();	
if (GotoPage.PageNo > 0 && GotoPage.PageNo <= textControl1.Pages)
{
    TXTextControl.InputPosition InputPosition = 
        new TXTextControl.InputPosition(GotoPage.PageNo,1,0);
    textControl1.InputPosition = InputPosition;
}
else
{
    MessageBox.Show("Page number outside valid range.");
}
[Visual Basic]
PageNo = InputBox("Page no.", "Go to page", "1")PageNo = I
If PageNo > 0 And PageNo <= TextControl1.Pages Then
    Dim InputPosition As New TXTextControl.InputPosition(PageNo, 1, 0)
    TextControl1.InputPosition = InputPosition
Else
    MsgBox("Page number outside valid range.", MsgBoxStyle.Exclamation)
End If
[Delphi]
procedure Form1.mnuPage_Click(sender: System.Object; e: System.EventArgs);
var
    PageNo : Integer;
    InputPosition : TXTextControl.InputPosition;
begin
    PageNo := StrToInt(InputBox('Page no.', 'Go to page', '1'));
    if ((PageNo > 0) And (PageNo < TextControl1.Pages)) then begin
        InputPosition := TXTextControl.InputPosition.Create(PageNo, 1, 0);
        TextControl1.InputPosition := InputPosition;
    end
    else begin
        MessageBox.Show('Page number outside valid range.');
    end;
end;

Note that the InputPosition.Page property requires the ViewMode property to be set to PageView. In all other modes, text is displayed continuously as a single page, so the property will always have a value of 1.

<< Previous