RichTextBox.SelectionProtected Eigenschaft

Definition

Ruft einen Wert ab, der angibt, ob die aktuelle Textauswahl geschützt ist, oder legt diesen fest.

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

Eigenschaftswert

true, wenn die aktuelle Auswahl Änderungen am Inhalt verhindert, andernfalls false. Der Standardwert ist false.

Attribute

Beispiele

Im folgenden Codebeispiel wird veranschaulicht, wie geschützter Text in der RichTextBox mithilfe der SelectionProtected -Eigenschaft angegeben wird. Dieses Beispiel erfordert, dass dem Formular ein RichTextBox Steuerelement mit dem Namen richTextBox1hinzugefügt wurde und dem RichTextBox Steuerelement Text hinzugefügt wurde, der das Wort "RichTextBox" enthält.

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

Hinweise

Wenn derzeit kein Text ausgewählt ist, wird die Schutzeinstellung auf den Absatz angewendet, in dem die Einfügemarke angezeigt wird, und auf den gesamten Text, der nach der Einfügemarke in das Steuerelement eingegeben wird. Die Schutzeinstellung gilt, bis die Eigenschaft in einen anderen Wert geändert wird oder die Einfügemarke in einen anderen Absatz innerhalb des Steuerelements verschoben wird.

Wenn Text innerhalb des Steuerelements ausgewählt ist, wird der Wert dieser Eigenschaft auf den markierten Text und den nach der Textauswahl eingegebenen Text angewendet. Sie können diese Eigenschaft verwenden, um zu verhindern, dass der Benutzer Textabschnitte innerhalb des Steuerelements ändert.

Wenn diese Eigenschaft auf truefestgelegt ist, wird das Protected Ereignis ausgelöst, wenn der Benutzer versucht, die aktuelle Textauswahl zu ändern.

Hinweis

Diese Eigenschaft gibt nur zurück true , wenn die gesamte Auswahl innerhalb des Steuerelements geschützte Inhalte enthält.

Gilt für:

Weitere Informationen