+ Reply to Thread
Results 1 to 2 of 2

Thread: Protect part of the textbox or richbox

  1. #1
    Junior Member
    Join Date
    Apr 2012
    Posts
    17

    Protect part of the textbox or richbox

    Sometimes i need to protect part of the textbox or richbox , like for example : http:// <<< you would like to keep that protect and no matter what so user can't delete it.

    How can i achieve that ?
    Last edited by jemmy; 10-31-2012 at 03:22 AM.

  2. #2
    Junior Member
    Join Date
    May 2012
    Posts
    36
    To achieve that , there are two ways.
    1) Either using textbox
    2) Or using a richtextbox << the easiest one.

    On Form_Load , type :
    Code:
            richTextBox1.Text = "http://";
            richTextBox1.SelectAll();
            richTextBox1.SelectionProtected = true;
            richTextBox1.SelectionStart = richTextBox1.Text.Length;
    For textbox :
    Code:
        string protected_text= "http://";
    
        private void textBox1_TextChanged(object sender, EventArgs e) {
            if (!textBox1.Text.StartsWith(protected_text)) {
                textBox1.Text = protected_text;
                textBox1.SelectionStart = textBox1.Text.Length;
            }
        }

+ Reply to Thread

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts