Partilhar via


Como: Posicionar o Cursor no Começo ou Final de um Texto em um Controle de TextBox

This example shows how to position the cursor at the beginning or end of the text contents of a TextBox control.

Exemplo

The following Extensible Application Markup Language (XAML) code describes a TextBox control and assigns it a Name.

<TextBox
  Name="tbPositionCursor"
>
  Here is some text in my text box...
</TextBox>

To position the cursor at the beginning of the contents of a TextBox control, call the Select method and specify the selection start position of 0, and a selection length of 0.

tbPositionCursor.Select(0, 0)
tbPositionCursor.Select(0, 0);

To position the cursor at the end of the contents of a TextBox control, call the Select method and specify the selection start position equal to the length of the text content, and a selection length of 0.

tbPositionCursor.Select(tbPositionCursor.Text.Length, 0)
tbPositionCursor.Select(tbPositionCursor.Text.Length, 0);

Consulte também

Conceitos

Visão geral sobre TextBox

Visão geral de RichTextBox