I'll try to be as specific as possible. I'm using visual basic 2010 c# express edition. I'm trying to create a textbox that is filled with information from the program. Suppose I put the text "Hello" in the textbox, when I run it, the form has a textbox saying Hello. Here, the user can select the text and copy it. Basically, when the mouse goes over the textbox, it changes appearance and the textbox is interactive. What I need to make is the textbox as not-interactive. In the textbox properties, there is an option called "Enabled". If I make it as False, all my requirements are satisfied. But the textbox is greyed out. Is there any way to get "Enabled" to false and still make the textbox look not greyed out. My query is regarding aesthetics.
-
You cannot change a disabled textbox color unless you override the OnPaint event... scroll down http://stackoverflow.com/questions/276179/how-to-change-the-font-color-of-a-disabled-textbox – Paul Zahra Mar 09 '15 at 13:13
-
1Replace your `TextBox` by a `Label`! You can __style it to look just like__ a `TextBox`. Set `AutoSize=false; ! - BTW: Imo your goal as it is against all UI guidelines, I don't like it but your users will __hate__ it.. – TaW Mar 09 '15 at 15:55
-
Does this answer your question? [How to change the font color of a disabled TextBox?](https://stackoverflow.com/questions/276179/how-to-change-the-font-color-of-a-disabled-textbox) – Ivan Nov 22 '20 at 00:32
5 Answers
You can make the textbox readonly:
Creating a Read-Only Text Box (Windows Forms)
To make the background gray, you probably need to change the background color:
txtFoo.BackColor = ...;
And if you do no want to make the text selectable, set Enabled = false;

- 27,590
- 8
- 64
- 84
-
1Even after making Read-only true, the text is selectable and the cursor is active. I need no-interactivity with text. As I said, it needs to look like Enabled=true. But needs to work like Enabled=false – zoobiezoobie Mar 09 '15 at 12:49
-
You have to set it Enabled = false and than change the txtFoo.BackColor = ...; – Peter Mar 09 '15 at 12:55
You can create your own control that will look exactly like a TextBox
but will be static. It's very easy to achieve that. Right-click on your project name in Solution Explorer and choose: Add > New Item... > Custom Control. You can name it somehow, e.g. DisabledTextBox
.
Here's the full code of the new control.
public partial class DisabledTextBox : Control
{
public DisabledTextBox()
{
InitializeComponent();
DoubleBuffered = true; // To avoid flickering
}
protected override void OnPaint(PaintEventArgs pe)
{
pe.Graphics.Clear(SystemColors.Window); // White background
pe.Graphics.DrawRectangle(SystemPens.ActiveBorder, new Rectangle(0, 0, Width - 1, Height - 1)); // Gray border
pe.Graphics.DrawString(Text, Font, SystemBrushes.WindowText, 1, 3); // Our text
}
protected override void OnTextChanged(EventArgs e)
{
base.OnTextChanged(e);
Invalidate(); // We want to repaint our control when text changes
}
protected override void OnSizeChanged(EventArgs e)
{
base.OnSizeChanged(e);
Height = Font.Height + 7; // This limit the height of our control so it will beahave like a normal TextBox
}
}
When you compile it, your new control will be available in Toolbox, so you can use like any other control. It will look exactly like TextBox.

- 1,892
- 1
- 11
- 18
-
Thank you very much. You gave me a way in. Now I'll just refine it till I get what I want. – zoobiezoobie Mar 09 '15 at 13:54
-
Sorry I cant up vote you. I dont have any reputation. Still, I appreciate your solution. Thanks – zoobiezoobie Mar 09 '15 at 13:56
-
Beware teh downvoting post police! +1 it seems like a bit of overkill, especially as I gave a link to an SO post which just overrides the OnPaint event of the textbox and achieves what the poster wanted, but I wouldn't give it -1 for not being the best possible solution, although many would. – Paul Zahra Mar 09 '15 at 14:01
I was looking for the easy solution to this question>
Here is what worked for me:
textBox Enabled property -- true
textBox ReadOnly property -- true
And below line of code to get rid of they greyed out area.
public Test_class()
{
InitializeComponent();
textBox.BackColor = System.Drawing.SystemColors.Window;
}
Yes, the user still can select the value in the text box but not entering a new value or edit old one.
Cheers!

- 399
- 2
- 5
- 18