Files
docs-desktop/dotnet-desktop-guide/framework/wpf/controls/position-the-cursor-at-the-beginning-or-end-of-text.md
T
Pooja PoojariandAndy De George 6d665a13bd US-1889327: Updated H2 headings. (#1323)
* Updated H2 headings for US-1889327.

* Review edits.

* Apply suggestions from code review

Co-authored-by: Andy (Steve) De George <[email protected]>
2022-03-04 18:48:05 +00:00

2.4 KiB

title, description, ms.date, ms.custom, dev_langs, helpviewer_keywords, ms.assetid
title description ms.date ms.custom dev_langs helpviewer_keywords ms.assetid
How to: Position the Cursor at the Beginning or End of Text in a TextBox Control Learn how to position the cursor at the beginning or end of the text contents of a Windows Presentation Foundation TextBox control. 03/30/2017 devdivchpfy22
csharp
vb
positioning cursor [WPF]
TextBox control [WPF], positioning cursor
cursor [WPF], positioning
c771a0b8-c6b4-4240-aecd-a21d0ba51a2e

How to: Position the Cursor at the Beginning or End of Text in a TextBox Control

This example shows how to position the cursor at the beginning or end of the text contents of a xref:System.Windows.Controls.TextBox control.

Define a TextBox control

The following [!INCLUDETLA#tla_xaml] code describes a xref:System.Windows.Controls.TextBox control and assigns it a Name.

[!code-xamlTextBox_MiscCode#_MoveCursorXAML]

Position the cursor at the beginning

To position the cursor at the beginning of the contents of a xref:System.Windows.Controls.TextBox control, call the xref:System.Windows.Controls.TextBox.Select%2A method and specify the selection start position of 0, and a selection length of 0.

[!code-csharpTextBox_MiscCode#_CursorToStart] [!code-vbTextBox_MiscCode#_CursorToStart]

Position the cursor at the end

To position the cursor at the end of the contents of a xref:System.Windows.Controls.TextBox control, call the xref:System.Windows.Controls.TextBox.Select%2A method and specify the selection start position equal to the length of the text content, and a selection length of 0.

[!code-csharpTextBox_MiscCode#_CursorToEnd] [!code-vbTextBox_MiscCode#_CursorToEnd]

See also