RichTextBox.SelectionProtected Egenskap
Definition
Viktigt
En del information gäller för förhandsversionen av en produkt och kan komma att ändras avsevärt innan produkten blir allmänt tillgänglig. Microsoft lämnar inga garantier, uttryckliga eller underförstådda, avseende informationen som visas här.
Hämtar eller anger ett värde som anger om den aktuella textmarkeringen är skyddad.
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
Egenskapsvärde
trueom den aktuella markeringen förhindrar ändringar i innehållet; annars . false Standardvärdet är false.
- Attribut
Exempel
I följande kodexempel visas hur du anger skyddad text i RichTextBox egenskapen med hjälp av egenskapen SelectionProtected . Det här exemplet kräver att en RichTextBox kontroll med namnet richTextBox1, har lagts till i formuläret och att RichTextBox kontrollen har lagt till text som innehåller ordet "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
Kommentarer
Om ingen text är markerad tillämpas skyddsinställningen på det stycke där insättningspunkten visas och på all text som skrivs in i kontrollen efter insättningspunkten. Skyddsinställningen gäller tills egenskapen ändras till ett annat värde eller tills insättningspunkten flyttas till ett annat stycke i kontrollen.
Om text är markerad i kontrollen kommer den markerade texten och all text som angetts efter textmarkeringen att ha värdet för den här egenskapen tillämpat på den. Du kan använda den här egenskapen för att förhindra att användaren ändrar textavsnitt i kontrollen.
Om den här egenskapen är inställd trueProtected på genereras händelsen när användaren försöker ändra den aktuella textmarkeringen.
Note
Den här egenskapen returneras true endast om hela markeringen i kontrollen innehåller skyddat innehåll.