Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make TextBox uneditable

I want to make some TextBoxes on my form uneditable, but I want the text to be clear (black not gray) and that's why I do not want to use

myTextBox.Enabled = false;

Somehow I want it to be disabled but with non-gray fore-color.

Does anyone have any clue?

like image 213
Mahdi Tahsildari Avatar asked Jan 30 '13 06:01

Mahdi Tahsildari


People also ask

How do you make a TextBox non editable in asp net?

Add("readonly", "readonly"); From MSDN, The Text value of a TextBox control with the ReadOnly property set to true is sent to the server when a postback occurs, but the server does no processing for a read-only text box.

How do you make a TextBox Uneditable in WPF?

To prevent users from modifying the contents of a TextBox control, set the IsReadOnly attribute to true.


1 Answers

Using the TextBox.ReadOnly property

TextBox.ReadOnly = true; 

For a Non-Grey background you can change the TextBox.BackColor property to SystemColors.Window Color

textBox.BackColor = System.Drawing.SystemColors.Window; 

When this property is set to true, the contents of the control cannot be changed by the user at runtime. With this property set to true, you can still set the value of the Text property in code. You can use this feature instead of disabling the control with the Enabled property to allow the contents to be copied and ToolTips to be shown.

like image 154
Parimal Raj Avatar answered Oct 12 '22 11:10

Parimal Raj