RichTextBox.SelectionLength Propriedade
Definição
Importante
Algumas informações dizem respeito a um produto pré-lançado que pode ser substancialmente modificado antes de ser lançado. A Microsoft não faz garantias, de forma expressa ou implícita, em relação à informação aqui apresentada.
Obtém ou define o número de caracteres selecionados no controlo.
public:
virtual property int SelectionLength { int get(); void set(int value); };
[System.ComponentModel.Browsable(false)]
public override int SelectionLength { get; set; }
[<System.ComponentModel.Browsable(false)>]
member this.SelectionLength : int with get, set
Public Overrides Property SelectionLength As Integer
Valor de Propriedade
O número de caracteres selecionados na caixa de texto.
- Atributos
Exemplos
O exemplo de código seguinte demonstra como usar a SelectionLength propriedade para determinar se o texto está selecionado dentro do RichTextBox. Este exemplo exige que um RichTextBox controlo, chamado richTextBox1, tenha sido adicionado ao formulário. O exemplo também exige que richTextBox1 contenha texto selecionado no controlo.
private:
void ModifySelectedText()
{
// Determine if text is selected in the control.
if ( richTextBox1->SelectionLength > 0 )
{
// Set the color of the selected text in the control.
richTextBox1->SelectionColor = Color::Red;
// Set the font of the selected text to bold and underlined.
richTextBox1->SelectionFont = gcnew System::Drawing::Font( "Arial",10,static_cast<FontStyle>(FontStyle::Bold | FontStyle::Underline) );
// Protect the selected text from modification.
richTextBox1->SelectionProtected = true;
}
}
private void ModifySelectedText()
{
// Determine if text is selected in the control.
if (richTextBox1.SelectionLength > 0)
{
// Set the color of the selected text in the control.
richTextBox1.SelectionColor = Color.Red;
// Set the font of the selected text to bold and underlined.
richTextBox1.SelectionFont = new Font("Arial",10,FontStyle.Bold | FontStyle.Underline);
// Protect the selected text from modification.
richTextBox1.SelectionProtected = true;
}
}
Private Sub ModifySelectedText()
' Determine if text is selected in the control.
If (richTextBox1.SelectionLength > 0) Then
' Set the color of the selected text in the control.
richTextBox1.SelectionColor = Color.Red
' Set the font of the selected text to bold and underlined.
richTextBox1.SelectionFont = New Font("Arial", 10, FontStyle.Bold Or FontStyle.Underline)
' Protect the selected text from modification.
richTextBox1.SelectionProtected = True
End If
End Sub
Observações
Pode usar esta propriedade para determinar se algum carácter está atualmente selecionado no controlo da caixa de texto antes de realizar operações no texto selecionado. Também pode usar esta propriedade para determinar o número total de caracteres (incluindo espaços) que são selecionados ao executar tarefas de um único personagem num for ciclo.