RichTextBox.SelectionProtected Propriedade

Definição

Recebe ou define um valor que indica se a seleção de texto atual está protegida.

public:
 property bool SelectionProtected { bool get(); void set(bool value); };
[System.ComponentModel.Browsable(false)]
public bool SelectionProtected { get; set; }
[<System.ComponentModel.Browsable(false)>]
member this.SelectionProtected : bool with get, set
Public Property SelectionProtected As Boolean

Valor de Propriedade

true se a seleção atual impedir quaisquer alterações ao seu conteúdo; caso contrário, false. A predefinição é false.

Atributos

Exemplos

O exemplo de código seguinte demonstra como especificar texto protegido dentro do RichTextBox usando a SelectionProtected propriedade. Este exemplo exige que um RichTextBox controlo, chamado richTextBox1, tenha sido adicionado ao formulário e que o RichTextBox controlo tenha texto adicionado que contenha a palavra "RichTextBox."

private:
   void ProtectMySelectedText()
   {
      // Determine if the selected text in the control contains the word "RichTextBox".
      if (  !richTextBox1->SelectedText->Equals( "RichTextBox" ) )
      {
         // Search for the word RichTextBox in the control.
         if ( richTextBox1->Find( "RichTextBox", RichTextBoxFinds::WholeWord ) == -1 )
         {
            //Alert the user that the word was not foun and return.
            MessageBox::Show( "The text \"RichTextBox\" was not found!" );
            return;
         }
      }

      // Protect the selected text in the control from being altered.
      richTextBox1->SelectionProtected = true;
   }
private void ProtectMySelectedText()
{
   // Determine if the selected text in the control contains the word "RichTextBox".
   if(richTextBox1.SelectedText != "RichTextBox")
   {
      // Search for the word RichTextBox in the control.
      if(richTextBox1.Find("RichTextBox",RichTextBoxFinds.WholeWord)== -1)
      {
         //Alert the user that the word was not foun and return.
         MessageBox.Show("The text \"RichTextBox\" was not found!");
         return;
      }
   }
   // Protect the selected text in the control from being altered.
   richTextBox1.SelectionProtected = true;
}
Private Sub ProtectMySelectedText()
   ' Determine if the selected text in the control contains the word "RichTextBox".
   If richTextBox1.SelectedText <> "RichTextBox" Then
      ' Search for the word RichTextBox in the control.
      If richTextBox1.Find("RichTextBox", RichTextBoxFinds.WholeWord) = -1 Then
         'Alert the user that the word was not foun and return.
         MessageBox.Show("The text ""RichTextBox"" was not found!")
         Return
      End If
   End If
   ' Protect the selected text in the control from being altered.
   richTextBox1.SelectionProtected = True
End Sub

Observações

Se não houver texto selecionado no momento, a definição de proteção é aplicada ao parágrafo onde aparece o ponto de inserção e a todo o texto que é digitado no controlo após o ponto de inserção. A definição de proteção aplica-se até que a propriedade seja alterada para um valor diferente ou até que o ponto de inserção seja movido para um parágrafo diferente dentro do controlo.

Se o texto for selecionado dentro do controlo, o texto selecionado e qualquer texto inserido após a seleção do texto terão o valor desta propriedade aplicado. Pode usar esta propriedade para impedir que o utilizador modifique secções de texto dentro do controlo.

Se esta propriedade estiver definida para true, o Protected evento é ativado quando o utilizador tenta alterar a seleção de texto atual.

Note

Esta propriedade só retornará true se toda a seleção dentro do controlo contiver conteúdo protegido.

Aplica-se a

Ver também