Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disabling or making it readonly a part of the values in a Text Box (.net)

Tags:

c#

.net

winforms

I have a textbox (multiline) which has initial value, now when user tries to append values to it, he should not be able to modify the initial value. Is it possible in any way?

like image 349
Anil Avatar asked May 06 '11 11:05

Anil


People also ask

How do I make a TextBox ReadOnly in C#?

Set the TextBox control's ReadOnly property to true . With the property set to true , users can still scroll and highlight text in a text box without allowing changes.

How do I make a TextBox ReadOnly in WPF?

The IsReadOnly property of the TextBox sets the text box read only. By default, it is false. The MaxLength property of the TextBox sets the number of characters allowed to input in a text box.

Which control is read only control in asp net?

You can make the TextBox as read-only by setting the readonly attribute to the input element.


1 Answers

So if you have "lorem ipsum" in the box you want the user to be able to add to but not remove that text? If so then with a RichTextBox you can do this via a selection's .SelectionProtected property which will mark a region as effectively being read only.

rtBox.Select(0, (rtBox.Text = "I am fixed content").Length);
rtBox.SelectionProtected = true;
rtBox.AppendText(Environment.NewLine);
like image 80
Alex K. Avatar answered Oct 03 '22 09:10

Alex K.