現在選択されているテキストが保護されているかどうかを示す値を取得または設定します。
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);
プロパティ値
現在選択されているテキストが保護されている場合は true 。それ以外の場合は false 。既定値は false です。
解説
テキストが現在選択されていない場合、テキスト保護の設定は、カーソルがある段落と、カーソル位置以降にコントロールに入力されるすべてのテキストに適用されます。プロパティの値が変更されるまで、またはカーソル位置をコントロール内の別の段落に移動するまでの間は、このテキスト保護の設定が適用されます。
コントロール内でテキストが選択されている場合は、選択されているテキスト、およびテキストを選択した後に入力したすべてのテキストに対して、このプロパティの値が適用されます。このプロパティを使用して、コントロール内のテキスト部分をユーザーが変更できないように設定できます。
このプロパティが true に設定されている場合、現在選択されているテキストをユーザーが変更しようとすると Protected イベントが発生します。
メモ このプロパティは、コントロール内で選択されている内容の中に、保護された内容が含まれる場合だけ true を返します。
使用例
[Visual Basic, C#, C++] SelectionProtected プロパティを使用して、 RichTextBox 内で保護されるテキストを指定する方法を次の例に示します。この例は、 richTextBox1
という名前の RichTextBox コントロールがフォームに追加されていて、その RichTextBox コントロールには "RichTextBox" という単語が含まれるテキストが追加されていることを前提にしています。
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] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。
必要条件
プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ
参照
RichTextBox クラス | RichTextBox メンバ | System.Windows.Forms 名前空間 | Protected