RichTextBox.SelectionProtected Свойство

Определение

Получает или задает значение, определяющее, защищено ли текущее текстовое выделение.

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

Значение свойства

Значение true, если в текущее выделение нельзя внести изменение; в противном случае — false. Значение по умолчанию — false.

Атрибуты

Примеры

В следующем примере кода показано, как указать защищенный текст в с RichTextBox помощью SelectionProtected свойства . В этом примере требуется, чтобы RichTextBox элемент управления с именем richTextBox1был добавлен в форму, а RichTextBox к элементу управления добавлен текст, содержащий слово 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

Комментарии

Если в данный момент текст не выбран, параметр защиты применяется к абзацу, в котором отображается точка вставки, и ко всему тексту, введенном в элементе управления после точки вставки. Параметр защиты применяется до тех пор, пока свойство не изменится на другое значение или пока точка вставки не будет перемещена в другой абзац в элементе управления .

Если текст выделен в элементе управления, к выделенному тексту и любому тексту, введенного после выделения текста, будет применено значение этого свойства. Это свойство можно использовать, чтобы запретить пользователю изменять разделы текста в элементе управления .

Если для этого свойства задано значение true, Protected событие возникает, когда пользователь пытается изменить текущий выделенный текст.

Примечание

Это свойство возвращает true только в том случае, если весь выделенный фрагмент в элементе управления содержит защищенное содержимое.

Применяется к

См. также раздел