Hinweis
Für den Zugriff auf diese Seite ist eine Autorisierung erforderlich. Sie können versuchen, sich anzumelden oder das Verzeichnis zu wechseln.
Für den Zugriff auf diese Seite ist eine Autorisierung erforderlich. Sie können versuchen, das Verzeichnis zu wechseln.
Ruft einen Wert ab, der angibt, ob die aktuelle Textauswahl geschützt ist, oder legt diesen fest.
Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)
Syntax
'Declaration
Public Property SelectionProtected As Boolean
'Usage
Dim instance As RichTextBox
Dim value As Boolean
value = instance.SelectionProtected
instance.SelectionProtected = value
public bool SelectionProtected { get; set; }
public:
property bool SelectionProtected {
bool get ();
void set (bool value);
}
/** @property */
public boolean get_SelectionProtected ()
/** @property */
public void set_SelectionProtected (boolean value)
public function get SelectionProtected () : boolean
public function set SelectionProtected (value : boolean)
Eigenschaftenwert
true, wenn die aktuelle Auswahl Änderungen am Inhalt verhindert, andernfalls false. Der Standardwert ist false.
Hinweise
Wenn derzeit kein Text markiert ist, wird die Schutzeinstellung auf den Absatz angewendet, in dem sich die Einfügemarke befindet, sowie auf sämtlichen nach der Einfügemarke in das Steuerelement eingegebenen Text. Die Einstellung für den Schutz wird angewendet, bis die Eigenschaft auf einen anderen Wert geändert oder die Einfügemarke in einen anderen Abschnitt des Steuerelements verschoben wird.
Wenn Text im Steuerelement markiert ist, wird auf diesen und sämtlichen danach eingegebenen Text der Wert dieser Eigenschaft angewendet. Sie können mithilfe dieser Eigenschaft verhindern, dass Textabschnitte im Steuerelement durch Benutzer geändert werden.
Wenn diese Eigenschaft auf true festgelegt ist, wird bei einem Versuch, die aktuelle Textauswahl zu ändern, das Protected-Ereignis ausgelöst.
Hinweis
Diese Eigenschaft gibt nur true zurück, wenn die gesamte Auswahl im Steuerelement geschützten Inhalt enthält.
Beispiel
Im folgenden Beispiel wird die Verwendung der SelectionProtected-Eigenschaft zum Angeben von geschütztem Text in der RichTextBox veranschaulicht. Für dieses Beispiel ist es erforderlich, dass im Formular ein RichTextBox-Steuerelement mit der Bezeichnung richTextBox1 hinzugefügt wurde und im RichTextBox-Steuerelement Text hinzugefügt wurde, der das Wort "RichTextBox" enthält.
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
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->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.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
Plattformen
Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile für Pocket PC, Windows Mobile für Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.
Versionsinformationen
.NET Framework
Unterstützt in: 2.0, 1.1, 1.0
Siehe auch
Referenz
RichTextBox-Klasse
RichTextBox-Member
System.Windows.Forms-Namespace
Protected