none
Rich textbox RRS feed

  • Question

  • How do I protect a part of text in a rich textbox (not all of it just a part of text)?


    Donny

    Thursday, November 2, 2017 12:28 AM

Answers

  •  You have to select the text you want protected and then set the RichTextBox.SelectionProtected property to True.  Then you can un-select the text.  Try this in a new form project with 1 RichTextBox added to the form.  The first line will be protected so you can not change it.

    Public Class Form1
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            RichTextBox1.Text = "Here is some text that is protected" & vbNewLine & "and here is some that is not protected."
    
            RichTextBox1.Find("Here is some text that is protected") 'use one of these methods or properties to select the text you want to protect (Find, Select, SelectionStart and SelectionLength)
            RichTextBox1.SelectionProtected = True 'now set the SelectionProtected property to True to protect the selected text
            RichTextBox1.Select(0, 0) 'reset the selection if you don't want the protected text to be selected after done
        End Sub
    End Class
    


    If you say it can`t be done then i`ll try it

    Thursday, November 2, 2017 12:45 AM

All replies

  •  You have to select the text you want protected and then set the RichTextBox.SelectionProtected property to True.  Then you can un-select the text.  Try this in a new form project with 1 RichTextBox added to the form.  The first line will be protected so you can not change it.

    Public Class Form1
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            RichTextBox1.Text = "Here is some text that is protected" & vbNewLine & "and here is some that is not protected."
    
            RichTextBox1.Find("Here is some text that is protected") 'use one of these methods or properties to select the text you want to protect (Find, Select, SelectionStart and SelectionLength)
            RichTextBox1.SelectionProtected = True 'now set the SelectionProtected property to True to protect the selected text
            RichTextBox1.Select(0, 0) 'reset the selection if you don't want the protected text to be selected after done
        End Sub
    End Class
    


    If you say it can`t be done then i`ll try it

    Thursday, November 2, 2017 12:45 AM
  • Perfect! Thank you.

    Donny

    Thursday, November 2, 2017 1:02 AM
  • Perfect! Thank you.

    Donny


     You're welcome.  8)

    If you say it can`t be done then i`ll try it

    Thursday, November 2, 2017 1:08 AM