Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In a textbox, protect the first words, but allow adding/editing to text past those words

So I have a textbox in C# (Using .NET forms) where I am going to accept a users string for some input.

This string already has text (arguments) at the beginning that will exist at the beginning of the string no matter what. It must be there. I want them to be aware of this, but not be able to delete the words from the textbox (so they wont think theyve deleted it already when its going to be there anyways)

So these first arguments must not be able to be deleted or edited.

Any text after these arguments can be added or modified freely as normal.

Is this possible in C#?

like image 413
MintyAnt Avatar asked Mar 26 '12 21:03

MintyAnt


1 Answers

Assuming WinForms, you can use a RichTextBox control instead. Set the Multiline=False property and here is an example to lock the first characters:

richTextBox1.Text = "LOCKED";
richTextBox1.SelectAll();
richTextBox1.SelectionProtected = true;

or this, which will only lock the first six characters "LOCKED", but allow the user to change the rest of the sentence:

richTextBox1.Text = "LOCKED information";
richTextBox1.Select(0, 6);
richTextBox1.SelectionProtected = true;
like image 100
LarsTech Avatar answered Nov 19 '22 03:11

LarsTech