Export (0) Print
Expand All

RichTextBox.SelectionProtected Property

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

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)

public bool SelectionProtected { get; set; }
/** @property */
public boolean get_SelectionProtected ()

/** @property */
public void set_SelectionProtected (boolean value)

public function get SelectionProtected () : boolean

public function set SelectionProtected (value : boolean)

Not applicable.

Property Value

true if the current selection prevents any changes to its content; otherwise, false. The default is false.

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.

NoteNote:

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

The following code example demonstrates how to specify protected text within the RichTextBox using the SelectionProtected property. 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 != "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.get_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.set_SelectionProtected(true);
} //ProtectMySelectedText

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft