共用方式為


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

備註

若目前未選取任何文字,保護設定會套用於插入點出現的段落及插入點後輸入控制項的所有文字。 保護設定會持續適用,直到屬性被更改為其他值,或插入點移至控制項內的其他段落。

若在控制項內選取文字,所選文字及後輸入的任何文字都會套用此屬性的值。 你可以利用這個特性來防止使用者修改控制項內的文字區段。

若此屬性設為 trueProtected 當使用者嘗試更改當前文字選擇時,事件會被觸發。

備註

只有當控制範圍內的整個選擇都包含受保護內容時,這個屬性才會回傳 true

適用於

另請參閱