* 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
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 |
|
|
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]