RichTextBox.SelectionProtected RichTextBox.SelectionProtected RichTextBox.SelectionProtected RichTextBox.SelectionProtected Property

定义

获取或设置一个值,通过该值指示是否保护当前选定文本。Gets or sets a value indicating whether the current text selection is protected.

public:
 property bool SelectionProtected { bool get(); void set(bool value); };
[System.ComponentModel.Browsable(false)]
public bool SelectionProtected { get; set; }
member this.SelectionProtected : bool with get, set
Public Property SelectionProtected As Boolean

属性值

如果禁止更改当前选择的任何内容,则为 true;否则为 falsetrue if the current selection prevents any changes to its content; otherwise, false. 默认值为 falseThe default is false.

示例

下面的代码示例演示如何RichTextBox SelectionProtected使用属性指定中的受保护文本。The following code example demonstrates how to specify protected text within the RichTextBox using the SelectionProtected property. 此示例要求RichTextBox已将名为richTextBox1的控件添加到窗体,并且RichTextBox该控件具有添加到其中的包含单词 "RichTextBox" 的文本。This example requires that a RichTextBox control, named richTextBox1, has been added to the form and that the RichTextBox control has text added to it that contains the word "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

注解

如果当前未选择任何文本,则保护设置将应用于插入点所在的段落以及插入点之后键入到控件中的所有文本。If no text is currently selected, the protection setting is applied to the paragraph in which the insertion point appears and to all text that is typed into the control after the insertion point. 在将属性更改为其他值或将插入点移动到控件内的不同段落之前,将应用保护设置。The protection setting applies until the property is changed to a different value or until the insertion point is moved to a different paragraph within the control.

如果在控件中选择文本,则选定文本和在选择文本后输入的任何文本都将应用此属性的值。If text is selected within the control, the selected text and any text entered after the text selection will have the value of this property applied to it. 您可以使用此属性来防止用户修改控件中的部分文本。You can use this property to prevent the user from modifying sections of text within the control.

如果将此属性设置为true Protected ,则当用户尝试更改当前所选内容时,将引发事件。If this property is set to true, the Protected event is raised when the user attempts to change the current text selection.

备注

仅当控件中true的整个选定内容包含受保护的内容时,此属性才会返回。This property will return true only if the entire selection within the control contains protected content.

适用于

另请参阅