EN
Il contenuto non è disponibile nella lingua di destinazione, ma solo in inglese.

RichTextBox.SelectionProtected Property

Gets or sets a value indicating whether the current text selection is protected.

[Visual Basic]
Public Property SelectionProtected As Boolean
[C#]
public bool SelectionProtected {get; set;}
[C++]
public: __property bool get_SelectionProtected();
public: __property void set_SelectionProtected(bool);
[JScript]
public function get SelectionProtected() : Boolean;
public function set SelectionProtected(Boolean);

Property Value

true if the current text selection is protected; otherwise, false. The default is false.

Remarks

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.

If this property is set to true, the Protected event is raised when the user attempts to change the current text selection.

Note   This property will return true only if the entire selection within the control contains protected content.

Example

[Visual Basic, C#, C++] The following example demonstrates how to specify protected text within the RichTextBox using the SelectionProtected property. This example assumes 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".

[Visual Basic] 
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

[C#] 
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;
}

[C++] 
private:
    void ProtectMySelectedText()
    {
        // Determine if the selected text in the control contains the word "RichTextBox".
        if(!richTextBox1->SelectedText->Equals(S"RichTextBox"))
        {
            // Search for the word RichTextBox in the control.
            if(richTextBox1->Find(S"RichTextBox",RichTextBoxFinds::WholeWord)== -1)
            {
                //Alert the user that the word was not foun and return.
                MessageBox::Show(S"The text \"RichTextBox\" was not found!");
                return;
            }
        }
        // Protect the selected text in the control from being altered.
        richTextBox1->SelectionProtected = true;
    }

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

RichTextBox Class | RichTextBox Members | System.Windows.Forms Namespace | Protected

Mostra: