How can I disable a textbox without fading text?

Is there a way to get all the properties !enabled

textbox

except the faded text?

I can not use Label

, because I want to textbox

was enabled

in the end. I can't use readonly

because I don't want the custom cursor to appear inside.

+3


source to share


2 answers


Use SystemColor instead of KnownColor:



Color color = textbox1.BackColor ;
textbox1.BackColor = System.Drawing.Color.FromArgb(color.A, color.R, color.G, color.B);

color = textbox1.ForeColor ;
textbox1.ForeColor = System.Drawing.Color.FromArgb(color.A, color.R, color.G, color.B);

      

+2


source


It would be better to have both Label

and TextBox

in the same place.

Hide TextBox

and show content in Label

until you're ready to edit it. Hide Label

and show at this point TextBox

.

Otherwise, you will have to subclass TextBox

and override the method OnPaint

, somewhat as follows:



protected override void OnPaint(PaintEventArgs e)
{
     SolidBrush drawBrush = new SolidBrush(ForeColor); //Use the ForeColor property
     // Draw string to screen.
     e.Graphics.DrawString(Text, Font, drawBrush, 0f,0f); //Use the Font property
}

      

Have a look at this answer and link.

+3


source







All Articles