Files
docs-desktop/dotnet-desktop-guide/framework/wpf/controls/position-the-cursor-at-the-beginning-or-end-of-text.md
T
Andy (Steve) De George be103da07e Replace various WPF include files with content (#1335)
* net-current-v30plus-md.md

* net-current-v40plus-md.md

* tla2sharptla-ui-md.md

* tla2sharptla-uiautomation-md.md

* tla2sharptla-winclient-md.md

* tla2sharptla-xaml-md.md

* tlasharptla-ui-md.md

* tlasharptla-uiautomation-md.md

* tlasharptla-winclient-md.md

* tlasharptla-xaml-md.md

* fix warnings
2022-03-16 12:14:11 -04:00

2.3 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 Extensible Application Markup Language (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