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

屬性

範例

下列程式碼範例示範如何使用 屬性,在 中 RichTextBoxSelectionProtected 指定受保護的文字。 這個範例會要求 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

適用於

另請參閱