--- title: "How to: Position the Cursor at the Beginning or End of Text in a TextBox Control" description: Learn how to position the cursor at the beginning or end of the text contents of a Windows Presentation Foundation TextBox control. ms.date: "03/30/2017" dev_langs: - "csharp" - "vb" helpviewer_keywords: - "positioning cursor [WPF]" - "TextBox control [WPF], positioning cursor" - "cursor [WPF], positioning" ms.assetid: 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 control. ## Example The following [!INCLUDE[TLA#tla_xaml](../../../includes/tlasharptla-xaml-md.md)] code describes a control and assigns it a Name. [!code-xaml[TextBox_MiscCode#_MoveCursorXAML](~/samples/snippets/csharp/VS_Snippets_Wpf/TextBox_MiscCode/CSharp/Window1.xaml#_movecursorxaml)] ## Example To position the cursor at the beginning of the contents of a control, call the method and specify the selection start position of 0, and a selection length of 0. [!code-csharp[TextBox_MiscCode#_CursorToStart](~/samples/snippets/csharp/VS_Snippets_Wpf/TextBox_MiscCode/CSharp/Window1.xaml.cs#_cursortostart)] [!code-vb[TextBox_MiscCode#_CursorToStart](~/samples/snippets/visualbasic/VS_Snippets_Wpf/TextBox_MiscCode/VisualBasic/Window1.xaml.vb#_cursortostart)] ## Example To position the cursor at the end of the contents of a control, call the method and specify the selection start position equal to the length of the text content, and a selection length of 0. [!code-csharp[TextBox_MiscCode#_CursorToEnd](~/samples/snippets/csharp/VS_Snippets_Wpf/TextBox_MiscCode/CSharp/Window1.xaml.cs#_cursortoend)] [!code-vb[TextBox_MiscCode#_CursorToEnd](~/samples/snippets/visualbasic/VS_Snippets_Wpf/TextBox_MiscCode/VisualBasic/Window1.xaml.vb#_cursortoend)] ## See also - [TextBox Overview](textbox-overview.md) - [RichTextBox Overview](richtextbox-overview.md)