다음을 통해 공유


RichTextBox.SelectionProtected 속성

현재 텍스트 선택 영역이 보호되는지 여부를 나타내는 값을 가져오거나 설정합니다.

네임스페이스: System.Windows.Forms
어셈블리: System.Windows.Forms(system.windows.forms.dll)

구문

‘선언
Public Property SelectionProtected As Boolean
‘사용 방법
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)

속성 값

현재 선택 영역의 내용을 변경할 수 없으면 true이고, 그렇지 않으면 false입니다. 기본값은 false입니다.

설명

선택된 텍스트가 없으면 삽입 지점이 있는 단락과 삽입 지점 다음에 컨트롤에 입력된 모든 텍스트에 대해 이 보호 설정이 적용됩니다. 해당 속성이 다른 값으로 변경되거나 삽입 지점이 컨트롤 내의 다른 단락으로 이동할 때까지 보호 설정이 적용됩니다.

컨트롤 내에서 텍스트를 선택하는 경우 선택한 텍스트 및 텍스트를 선택한 다음 입력한 모든 텍스트는 선택한 텍스트에 적용된 이 속성의 값을 사용합니다. 이 속성을 사용하면 컨트롤 내의 텍스트 부분을 수정할 수 없도록 할 수 있습니다.

이 속성이 true로 설정된 경우 현재 텍스트 선택 영역을 변경하려고 하면 Protected 이벤트가 발생합니다.

참고

이 속성은 컨트롤 내의 전체 선택 영역에 보호된 내용이 포함된 경우에만 true를 반환합니다.

예제

다음 코드 예제에서는 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
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

플랫폼

Windows 98, Windows 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

.NET Framework에서 모든 플래폼의 모든 버전을 지원하지는 않습니다. 지원되는 버전의 목록은 시스템 요구 사항을 참조하십시오.

버전 정보

.NET Framework

2.0, 1.1, 1.0에서 지원

참고 항목

참조

RichTextBox 클래스
RichTextBox 멤버
System.Windows.Forms 네임스페이스
Protected