Freigeben über


RichTextBox.SelectionProtected Eigenschaft

Definition

Dient zum Abrufen oder Festlegen eines Werts, der angibt, ob die aktuelle Textauswahl geschützt ist.

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

truewenn die aktuelle Auswahl Änderungen am Inhalt verhindert; andernfalls . false Der Standardwert lautet false.

Attribute

Beispiele

Im folgenden Codebeispiel wird veranschaulicht, wie geschützter Text in der RichTextBox Verwendung der SelectionProtected Eigenschaft angegeben wird. Dieses Beispiel erfordert, dass dem Formular ein RichTextBox Steuerelement mit dem Namen richTextBox1hinzugefügt wurde und dass dem Steuerelement Text hinzugefügt wurde, der RichTextBox 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 zurzeit 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 bis die Einfügemarke in einen anderen Absatz innerhalb des Steuerelements verschoben wird.

Wenn Text innerhalb des Steuerelements markiert ist, wird der markierte Text und jeder Text, der nach der Textauswahl eingegeben wurde, den Wert dieser Eigenschaft zugewiesen. Sie können diese Eigenschaft verwenden, um zu verhindern, dass der Benutzer Abschnitte von Text innerhalb des Steuerelements ändert.

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

Hinweis

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

Gilt für:

Weitere Informationen