# Viewing, Zooming, and Navigation

> Set ViewMode and ZoomFactor, show control characters, go to a page, scroll with ScrollLocation and find the visible page in a Windows Forms TextControl.

- **Product:** TX Text Control .NET for Windows Forms
- **Section:** Documentation
- **Kind:** Topic
- **Path:** TX Text Control .NET for Windows Forms > Document Editor > Viewing, Zooming, and Navigation
- **4069 words**
- **Web URL:** https://docs.textcontrol.com/tx-text-control-dotnet-winforms/document-editor/viewing/
- **LLMs URL:** https://docs.textcontrol.com/tx-text-control-dotnet-winforms/document-editor/viewing/llms.txt
- **LLMs-Full URL:** https://docs.textcontrol.com/tx-text-control-dotnet-winforms/document-editor/viewing/llms-full.txt

---

Whether the editor shows pages like a printout or text that flows with the width of the form, how large it draws them and where the user is in a long document are settings of the `TextControl`. Users change them in the **View** tab of the ribbon and the status bar; your code sets them with a few properties, moves the input position to a page and reacts when the user zooms or turns a page.

The code runs in *Form1.cs* with a `TextControl` named `textControl1`, the editor of [Create Your First Windows Forms Application](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/getting-started/document-editor/first-application/llms-full.txt).

### Choose a View Mode

[ViewMode](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/textcontrol/viewmode-property/llms-full.txt) decides how the document is laid out on the screen:

| Value | The editor shows |
|---|---|
| `PageView` | Pages with gaps and a desktop background, formatted with the page size and margins; headers and footers are displayed |
| `Normal` | Text formatted with the page size and margins, without the page view; headers and footers can be inserted but aren't displayed |
| `FloatingText` | Text as wide as the control, with a vertical scroll bar for unlimited text; the page size, margins, headers and footers are ignored |
| `SimpleControl` | Text formatted to the width and height of the control; when it is full, no more text can be entered |

`PageView` is the view of a word processor and the only mode in which the editor counts pages. The following code sets it when the form opens:

```csharp
private void Form1_Load(object sender, EventArgs e)
{
    // Show pages like a printed document
    textControl1.ViewMode = ViewMode.PageView;
}
```

In page view, [BackgroundStyle](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/textcontrol/backgroundstyle-property/llms-full.txt) chooses the background around the pages: `ColorScheme` uses the color scheme of the system or the colors of [DisplayColors](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/textcontrol/displaycolors-property/llms-full.txt), and `ClassicColors` a dark gray. [ScrollBars](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/textcontrol/scrollbars-property/llms-full.txt) takes a value of the `System.Windows.Forms.ScrollBars` enumeration: `None`, `Horizontal`, `Vertical` or `Both`.

In `SimpleControl` mode, the control can also change its own width or height as the user types, like a text box that grows with its text. [Let the Control Grow With Its Content](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/document-editor/architecture/#let-the-control-grow-with-its-content) shows the `AutoControlSize` settings and events for this.

### Zoom the Document

Users zoom with the slider of the status bar, the zoom items of the **View** tab or Ctrl and the mouse wheel. In code, [ZoomFactor](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/textcontrol/zoomfactor-property/llms-full.txt) sets and returns the zoom factor in percent, and [Zoom](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/textcontrol/zoom-method/llms-full.txt) zooms to a factor or to a value of [ZoomOption](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/zoomoption/enumeration/llms-full.txt):

```csharp
private void zoomInButton_Click(object sender, EventArgs e)
{
    textControl1.Zoom(textControl1.ZoomFactor + 10);
}

private void pageWidthButton_Click(object sender, EventArgs e)
{
    // Fit the width of the page into the control
    textControl1.Zoom(ZoomOption.PageWidth);
}
```

- `ZoomOption.PageWidth` fits the width of a page into the control, `ZoomOption.WholePage` the current page, and `ZoomOption.TextWidth` the text of a line.
- In `PageView` and `Normal` mode, the factor can be from 10 up to `ushort.MaxValue` percent. In the other modes, it can be from 10 to 400 percent.
- After the zoom factor has changed, the `TextControl` raises [Zoomed](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/textcontrol/zoomed-event/llms-full.txt). A handler can show the new factor:

```csharp
private void textControl1_Zoomed(object sender, EventArgs e)
{
    zoomLabel.Text = $"{textControl1.ZoomFactor} %";
}
```

`zoomLabel` is a `Label` on the form. The blog article [Zoom Tricks: Disabling CTRL + MOUSE WHEEL and More](https://www.textcontrol.com/blog/2020/12/09/zoom-tricks-disabling-ctrl-mouse-wheel-and-more/) turns off zooming with the mouse wheel and adds keyboard shortcuts for zooming.

### Show Formatting Marks and Markers

Some characters and objects are invisible in a printed document but help while editing:

| Property | Shows |
|---|---|
| [ControlChars](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/textcontrol/controlchars-property/llms-full.txt) | All control characters, such as spaces, tabs and paragraph ends |
| [PermanentControlChars](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/textcontrol/permanentcontrolchars-property/llms-full.txt) | Selected control characters all the time, as a combination of [PermanentControlChar](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/permanentcontrolchar/enumeration/llms-full.txt) values such as `ParagraphEnd`, `ForcedPageBreak` or `SectionBreak` |
| [TextFrameMarkerLines](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/textcontrol/textframemarkerlines-property/llms-full.txt) | Marker lines around text frames without a border |
| [DrawingMarkerLines](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/textcontrol/drawingmarkerlines-property/llms-full.txt) | Marker lines around drawings |
| [DocumentTargetMarkers](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/textcontrol/documenttargetmarkers-property/llms-full.txt) | Markers at hypertext targets, such as bookmarks |

Users don't need code for these settings: the **View** tab, a [RibbonViewTab](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol-windows-forms-ribbon/ribbonviewtab/llms-full.txt), switches between **Print Layout** and **Draft** in its **Document Views** group, sets the zoom factor or fits the page, its width or the text width into the control in its **Zoom** group, shows and hides the rulers and the status bar in its **Toolbars** group, and turns table gridlines, bookmark markers, marker lines, control characters and frame anchors on and off in its **Show** group.

![The View tab of TX Text Control Words with the groups Document Views (Print Layout, Draft), Zoom (Zoom, 100 %, Full Page, Page Width, Text Width), Toolbars, Show and Application View.](https://docs.textcontrol.com/assets/img/tx-text-control-dotnet-winforms/view-tab-toolbars.b16b72fd.webp)

In code, a combination of permanent control characters is written with the bitwise OR operator:

```csharp
// Always show paragraph ends and page breaks
textControl1.PermanentControlChars = PermanentControlChar.ParagraphEnd | PermanentControlChar.ForcedPageBreak;
```

### Go to a Page

The input position has a page, a line and a column. Setting [InputPosition](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/textcontrol/inputposition-property/llms-full.txt) to a new [InputPosition](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/inputposition/llms-full.txt) moves the caret there, and [ScrollTo](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/inputposition/scrollto-method/llms-full.txt) scrolls it into view:

```csharp
private void goToPageButton_Click(object sender, EventArgs e)
{
    int page = 3;

    // Pages exist only in page view
    if (textControl1.ViewMode != ViewMode.PageView || page > textControl1.Pages)
    {
        return;
    }

    // Line 1, column 0 is the start of the page
    textControl1.InputPosition = new InputPosition(page, 1, 0);
    textControl1.InputPosition.ScrollTo(InputPosition.ScrollPosition.Top);
    textControl1.Focus();
}
```

[Pages](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/textcontrol/pages-property/llms-full.txt) returns the number of pages of the document. [Selections and Caret Position](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/document-editor/editing-text/selections/#read-the-input-position) describes the `InputPosition` constructor and `ScrollTo` in detail.

[GetPages](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/textcontrol/getpages-property/llms-full.txt) returns a [PageCollection](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/pagecollection/llms-full.txt) with a `Page` object per page, and `null` outside page view. [Page.Select](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/page/select-method/llms-full.txt) selects the text of a page, without its header and footer. For users, the [GotoDialog](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/gotodialog/llms-full.txt) is a modeless dialog box that moves the input position to a page, section, line, table or bookmark:

```csharp
private void goToDialogButton_Click(object sender, EventArgs e)
{
    GotoDialog dialog = new GotoDialog(textControl1);
    dialog.Show();
}
```

### React to the Position in the Document

[PageChanged](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/textcontrol/pagechanged-event/llms-full.txt) occurs when the input position moves to another page. [InputPosition.Page](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/inputposition/page-property/llms-full.txt) then returns the new page, in page view only:

```csharp
private void textControl1_PageChanged(object sender, EventArgs e)
{
    pageLabel.Text = $"Page {textControl1.InputPosition.Page} of {textControl1.Pages}";
}
```

The [StatusBar](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/statusbar/llms-full.txt) of TX Text Control shows the same information without code; see [Rulers and Status Bar](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/document-editor/ribbon-ui/rulers-status-bar/llms-full.txt). [HScroll](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/textcontrol/hscroll-event/llms-full.txt) and [VScroll](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/textcontrol/vscroll-event/llms-full.txt) occur when the user scrolls, and [ScrollLocation](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/textcontrol/scrolllocation-property/llms-full.txt) returns or sets the upper-left corner of the visible part of the document, in twips.

#### Scroll to a Text Position Without Moving the Caret

`InputPosition.ScrollTo` moves the caret first. To bring a text position into view and leave the caret where it is, set `ScrollLocation` to the position of the character:

```csharp
private void ScrollToTextPosition(int textPosition)
{
    Point location;

    // TextChars counts from 1, text positions from 0
    if (textPosition + 1 <= textControl1.TextChars.Count)
    {
        location = new Point(0, textControl1.TextChars[textPosition + 1].Bounds.Y);
    }
    else
    {
        // Past the end: scroll to the last line
        location = new Point(0, textControl1.Lines[textControl1.Lines.Count].TextBounds.Y);
    }

    textControl1.ScrollLocation = location;
}
```

The code works as follows:

- The text position is zero-based, as [Selection.Start](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/selection/start-property/llms-full.txt) and [InputPosition.TextPosition](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/inputposition/textposition-property/llms-full.txt) are. The indexer of [TextChars](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/textcontrol/textchars-property/llms-full.txt) counts characters from 1, so the character at a text position is `TextChars[textPosition + 1]`.
- [TextChar.Bounds](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/textchar/bounds-property/llms-full.txt) and [Line.TextBounds](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/line/textbounds-property/llms-full.txt) are given in twips from the upper-left corner of the document, the same coordinates as `ScrollLocation`.
- A position beyond the last character scrolls to the last line, which `Lines[Lines.Count]` returns from the one-based [Lines](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/textcontrol/lines-property/llms-full.txt) collection.

`Point` is the `System.Drawing.Point` structure.

#### Show the Page Number of the Visible Page

In a read-only viewer, users scroll instead of moving the caret, so `InputPosition.Page` and `PageChanged` stay on the page where the caret is. The page the user looks at is the page of the line in the middle of the control. [LineCollection.GetItem](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/linecollection/getitem-method/llms-full.txt) with a `Point`, in pixels from the upper-left corner of the control, returns the line displayed there, taking the scroll position into account. Update the display in the `VScroll` event:

```csharp
private void textControl1_VScroll(object sender, EventArgs e)
{
    // The line in the middle of the visible part
    Line line = textControl1.Lines.GetItem(new Point(0, textControl1.Height / 2));
    if (line == null || textControl1.ViewMode != ViewMode.PageView)
    {
        return;
    }

    int section = textControl1.GetPages()[line.Page].Section;
    pageLabel.Text = $"Page {line.Page} of {textControl1.Pages}, section {section} of {textControl1.Sections.Count}";
}
```

[Line.Page](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/line/page-property/llms-full.txt) is the number of the page, counted from 1. `GetPages()[number]` returns that [Page](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/page/llms-full.txt), and [Page.Section](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/page/section-property/llms-full.txt) the number of its section; when a page holds several sections, it is the first one, which sets the size and orientation of the page.

### Next Steps

- [Selections and Caret Position](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/document-editor/editing-text/selections/llms-full.txt): read and set the input position and the selection.
- [Sections and Page Layout](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/document-editor/sections/llms-full.txt): page sizes, margins and orientation that page view shows.
- [Rulers and Status Bar](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/document-editor/ribbon-ui/rulers-status-bar/llms-full.txt): the zoom slider and the page display of the status bar.
- [Printing and Print Preview](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/document-editor/printing/llms-full.txt): from the screen to paper.

---

## Nearby

- **Previous:** [Spell Checking and Hyphenation](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/document-editor/spell-checking/llms-full.txt)
- **Next:** [Printing and Print Preview](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/document-editor/printing/llms-full.txt)
