RichTextBox.SelectionProtected Propriété

Définition

Obtient ou définit une valeur indiquant si la sélection de texte actuelle est protégée.

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

Valeur de propriété

true si la sélection actuelle empêche toute modification de son contenu ; sinon, false. La valeur par défaut est false.

Attributs

Exemples

L’exemple de code suivant montre comment spécifier du texte protégé dans le à l’aide de RichTextBox la SelectionProtected propriété . Cet exemple nécessite qu’un RichTextBox contrôle, nommé richTextBox1, ait été ajouté au formulaire et qu’il y ait ajouté du RichTextBox texte qui contient le mot « 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

Remarques

Si aucun texte n’est actuellement sélectionné, le paramètre de protection est appliqué au paragraphe dans lequel le point d’insertion apparaît et à tout le texte tapé dans le contrôle après le point d’insertion. Le paramètre de protection s’applique jusqu’à ce que la propriété soit remplacée par une valeur différente ou jusqu’à ce que le point d’insertion soit déplacé vers un autre paragraphe dans le contrôle.

Si le texte est sélectionné dans le contrôle, la valeur de cette propriété est appliquée au texte sélectionné et à tout texte entré après la sélection de texte. Vous pouvez utiliser cette propriété pour empêcher l’utilisateur de modifier des sections de texte dans le contrôle.

Si cette propriété a la truevaleur , l’événement Protected est déclenché lorsque l’utilisateur tente de modifier la sélection de texte actuelle.

Notes

Cette propriété retourne true uniquement si l’ensemble de la sélection dans le contrôle contient du contenu protégé.

S’applique à

Voir aussi