3

Is there anyway of getting all of the properties of a !enabled textbox except the faded text?

I cannot use a Label because I want the textbox to be enabled eventually. I cannot use readonly because I do not want the user's cursor to appear within.

Phillip
  • 255
  • 1
  • 12

2 Answers2

3

It would be best to have both a Label and a TextBox in the same location.

Hide the TextBox and display the content in a Label until you are ready to edit it. At that point, hide the Label and show the TextBox.

Otherwise you'll have to subclass the TextBox, and override the OnPaint method, somewhat like the following:

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
}

Take a look at this answer and this link.

Community
  • 1
  • 1
Martin
  • 16,093
  • 1
  • 29
  • 48
  • Thanks, I was hoping I wouldn't have to create a custom textbox. I actually was thinking about using a label and textbox. I was hoping there was something _very_ simple. – Phillip Aug 04 '15 at 15:01
2

Use a 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);
Graffito
  • 1,658
  • 1
  • 11
  • 10