RichTextBox.SelectionProtected Vlastnost

Definice

Získá nebo nastaví hodnotu označující, zda je aktuální výběr textu chráněn.

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

Hodnota vlastnosti

truepokud aktuální výběr brání změnám jeho obsahu; v opačném případě . false Výchozí formát je false.

Atributy

Příklady

Následující příklad kódu ukazuje, jak zadat chráněný text v rámci RichTextBox pomocí SelectionProtected vlastnosti. Tento příklad vyžaduje, aby RichTextBox byl do formuláře přidán ovládací prvek s názvem richTextBox1a aby RichTextBox do něj byl přidán text obsahující slovo 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

Poznámky

Pokud není aktuálně vybrán žádný text, použije se nastavení ochrany na odstavec, ve kterém se kurzor zobrazuje, a na veškerý text, který je zadán do ovládacího prvku za kurzorem. Nastavení ochrany platí, dokud se vlastnost nezmění na jinou hodnotu nebo dokud se kurzor nepřesune do jiného odstavce v rámci ovládacího prvku.

Pokud je v ovládacím prvku vybrán text, bude u vybraného textu a všech textů zadaných po výběru textu použita hodnota této vlastnosti. Tuto vlastnost můžete použít k tomu, aby uživatel nemohl upravovat oddíly textu v ovládacím prvku.

Pokud je tato vlastnost nastavena na true, Protected událost se vyvolá, když se uživatel pokusí změnit aktuální výběr textu.

Poznámka

Tato vlastnost se vrátí true pouze v případě, že celý výběr v ovládacím prvku obsahuje chráněný obsah.

Platí pro

Viz také