RichTextBox.SelectedText Propriedade
Definição
Importante
Algumas informações se referem a produtos de pré-lançamento que podem ser substancialmente modificados antes do lançamento. A Microsoft não oferece garantias, expressas ou implícitas, das informações aqui fornecidas.
Obtém ou define o texto selecionado no RichTextBox.
public:
virtual property System::String ^ SelectedText { System::String ^ get(); void set(System::String ^ value); };
[System.ComponentModel.Browsable(false)]
public override string SelectedText { get; set; }
[<System.ComponentModel.Browsable(false)>]
member this.SelectedText : string with get, set
Public Overrides Property SelectedText As String
Valor da propriedade
Uma cadeia de caracteres que representa o texto selecionado no controle.
- Atributos
Exemplos
O exemplo de código a seguir demonstra como usar a SelectionBullet propriedade com o SelectionFont, SelectedTexte SelectionColor as propriedades para criar uma lista com marcadores em um RichTextBox controle. Este exemplo requer que um RichTextBox controle nomeado richTextBox1
seja criado em um formulário.
private:
void WriteTextToRichTextBox()
{
// Clear all text from the RichTextBox;
richTextBox1->Clear();
// Set the font for the opening text to a larger Arial font;
richTextBox1->SelectionFont = gcnew System::Drawing::Font( "Arial",16 );
// Assign the introduction text to the RichTextBox control.
richTextBox1->SelectedText = "The following is a list of bulleted items: \n";
// Set the Font for the first item to a smaller size Arial font.
richTextBox1->SelectionFont = gcnew System::Drawing::Font( "Arial",12 );
// Specify that the following items are to be added to a bulleted list.
richTextBox1->SelectionBullet = true;
// Set the color of the item text.
richTextBox1->SelectionColor = Color::Red;
// Assign the text to the bulleted item.
richTextBox1->SelectedText = "Apples \n";
// Apply same font since font settings do not carry to next line.
richTextBox1->SelectionFont = gcnew System::Drawing::Font( "Arial",12 );
richTextBox1->SelectionColor = Color::Orange;
richTextBox1->SelectedText = "Oranges \n";
richTextBox1->SelectionFont = gcnew System::Drawing::Font( "Arial",12 );
richTextBox1->SelectionColor = Color::Purple;
richTextBox1->SelectedText = "Grapes \n";
// End the bulleted list.
richTextBox1->SelectionBullet = false;
// Specify the font size and string for text displayed below bulleted list.
richTextBox1->SelectionFont = gcnew System::Drawing::Font( "Arial",16 );
richTextBox1->SelectedText = "Bulleted Text Complete!";
}
private void WriteTextToRichTextBox()
{
// Clear all text from the RichTextBox;
richTextBox1.Clear();
// Set the font for the opening text to a larger Arial font;
richTextBox1.SelectionFont = new Font("Arial", 16);
// Assign the introduction text to the RichTextBox control.
richTextBox1.SelectedText = "The following is a list of bulleted items:" + "\n";
// Set the Font for the first item to a smaller size Arial font.
richTextBox1.SelectionFont = new Font("Arial", 12);
// Specify that the following items are to be added to a bulleted list.
richTextBox1.SelectionBullet = true;
// Set the color of the item text.
richTextBox1.SelectionColor = Color.Red;
// Assign the text to the bulleted item.
richTextBox1.SelectedText = "Apples" + "\n";
// Apply same font since font settings do not carry to next line.
richTextBox1.SelectionFont = new Font("Arial", 12);
richTextBox1.SelectionColor = Color.Orange;
richTextBox1.SelectedText = "Oranges" + "\n";
richTextBox1.SelectionFont = new Font("Arial", 12);
richTextBox1.SelectionColor = Color.Purple;
richTextBox1.SelectedText = "Grapes" + "\n";
// End the bulleted list.
richTextBox1.SelectionBullet = false;
// Specify the font size and string for text displayed below bulleted list.
richTextBox1.SelectionFont = new Font("Arial", 16);
richTextBox1.SelectedText = "Bulleted Text Complete!";
}
Private Sub WriteTextToRichTextBox()
' Clear all text from the RichTextBox;
richTextBox1.Clear()
' Set the font for the opening text to a larger Arial font;
richTextBox1.SelectionFont = New Font("Arial", 16)
' Assign the introduction text to the RichTextBox control.
RichTextBox1.SelectedText = "The following is a list of bulleted items:" + ControlChars.Cr
' Set the Font for the first item to a smaller size Arial font.
richTextBox1.SelectionFont = New Font("Arial", 12)
' Specify that the following items are to be added to a bulleted list.
richTextBox1.SelectionBullet = True
' Set the color of the item text.
richTextBox1.SelectionColor = Color.Red
' Assign the text to the bulleted item.
richTextBox1.SelectedText = "Apples" + ControlChars.Cr
' Apply same font since font settings do not carry to next line.
richTextBox1.SelectionFont = New Font("Arial", 12)
richTextBox1.SelectionColor = Color.Orange
richTextBox1.SelectedText = "Oranges" + ControlChars.Cr
richTextBox1.SelectionFont = New Font("Arial", 12)
richTextBox1.SelectionColor = Color.Purple
richTextBox1.SelectedText = "Grapes" + ControlChars.Cr
' End the bulleted list.
richTextBox1.SelectionBullet = False
' Specify the font size and string for text displayed below bulleted list.
richTextBox1.SelectionFont = New Font("Arial", 16)
richTextBox1.SelectedText = "Bulleted Text Complete!"
End Sub