Make TextBox Unedited

I want to make some TextBox es in my form unedited, but I want the text be clear (black not gray) and therefore I don't want to use

myTextBox.Enabled = false;

Somehow I want it to be turned off, but with no gray color.

Does anyone have any clues?

+44
c # winforms textbox
Jan 30 '13 at 6:34
source share
6 answers

Using the TextBox.ReadOnly

 TextBox.ReadOnly = true; 

For a background without gray, you can change the TextBox.BackColor property to SystemColors.Window Color

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

If this property is set to true, the contents of the control cannot be modified by the user at run time. If this property is set to true, you can still set the value of the Text property in the code. You can use this instead of disabling the control using the Enabled property to allow copying of content and tooltips.

+73
Jan 30 '13 at 6:35
source share
β€” -

Use the ReadOnly property in a TextBox.

 myTextBox.ReadOnly = true; 

But remember: TextBoxBase.ReadOnly property

If this property is set to true, the contents of the control cannot be modified by the user at run time . If this property is set to true, you can set the value of the Text property in the code . You can use this function instead of disabling the control using the Enabled property, which allows you to copy content and tooltips. shown in the figure.

+12
Jan 30 '13 at 6:36
source share

You can try:

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

The last line is necessary only if you need a non-gray background color.

+4
Jan 30 '13 at 6:40
source share

If you want your TextBox uneditable, you must make it ReadOnly .

+3
Jan 30 '13 at 6:38
source share

If you want to do this using XAML, set the isReadOnly property to true .

+1
Dec 13 '16 at 23:22
source share

Just install in XAML:

  <TextBox IsReadOnly="True" Style="{x:Null}" /> 

Thus, the text will not be grayed out.

+1
Apr 3 '17 at 11:37 on
source share



All Articles