How to show dark font while Not Enabled ?

  • Thread starter Thread starter Rob
  • Start date Start date
R

Rob

I would like to show dark fonts (so that the text is readable and not greyed
out) in a text box, however, I do Not want the text box to be Enabled,
because I do not want the text box to ever have the focus. Can this be
accomplished ? It is looking like this cannot be done.

Thanks
 
why dno't just set the Font property to the color you want
and override keydown to disable keys in the textbox
 
The standard black font is fine, it is just that when you set Enabled =
False for the textbox, the text is greyed out to the point where it is very
hard to read.

I wonder why the ReadOnly property allows the textbox to have the focus ?

How would you set this ? >and override keydown to disable keys in the
textbox

And would it still allow the textbox to have the focus ?
 
You can change the ForeColor and BackColor properties after it has been
disabled, and it iwll change it.
 
I am using Windows forms and that is not working for me... maybe I am doing
something wrong ?
 
Ok, I will buy that... but there still appears to be no way to turn off the
"grey out attribute" when a textbox is not enabled....
Thanks...
 
Ah but sure it can be done. I had the same problem and came up with the
following solution. You create a textbox inherited from a "normal" textbox.
In that textbox control, you override the OnPaint method. This is C#. I have
the same example in VB, but not on the computer I'm currently working on.
But this should give you the general idea.

using System;
using System.Drawing;
using System.ComponentModel;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using System.Windows.Forms;

namespace UserControls
{
[ToolboxBitmap(typeof(System.Windows.Forms.TextBox))]
public partial class FoBTextBox : TextBox
{
protected override void OnPaint(PaintEventArgs e)
{
//First paint the control normally
base.OnPaint(e);
//Set new brush - Black in this case
SolidBrush brush = new SolidBrush(ForeColor);
//Draw text
e.Graphics.DrawString(Text, Font, brush, 0f, 1f);
//Dispose of brush
brush.Dispose();
}

private void OnFoBTextBox_EnabledChanged(object sender, EventArgs e)
{
if (this.Enabled)
{
//BackColor for enabled textbox
this.BackColor = System.Drawing.SystemColors.Window;
}
else
{
//BackColor for disabled textbox
this.BackColor = System.Drawing.SystemColors.InactiveBorder;
}

//Set textbox style to userpaint
this.SetStyle(ControlStyles.UserPaint, !this.Enabled);

//Invalidate to paint the control
this.Invalidate();
}
}
}


Good luck,

Johnny J.
 
Thanks Johnny,

So you are actually creating a new UserControl based on a textbox ?

I will work on it, but.... if you do happen to run across the VB code, I
would certainly appreciate a posting !


Johnny Jörgensen said:
Ah but sure it can be done. I had the same problem and came up with the
following solution. You create a textbox inherited from a "normal"
textbox. In that textbox control, you override the OnPaint method. This is
C#. I have the same example in VB, but not on the computer I'm currently
working on. But this should give you the general idea.

using System;
using System.Drawing;
using System.ComponentModel;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using System.Windows.Forms;

namespace UserControls
{
[ToolboxBitmap(typeof(System.Windows.Forms.TextBox))]
public partial class FoBTextBox : TextBox
{
protected override void OnPaint(PaintEventArgs e)
{
//First paint the control normally
base.OnPaint(e);
//Set new brush - Black in this case
SolidBrush brush = new SolidBrush(ForeColor);
//Draw text
e.Graphics.DrawString(Text, Font, brush, 0f, 1f);
//Dispose of brush
brush.Dispose();
}

private void OnFoBTextBox_EnabledChanged(object sender, EventArgs e)
{
if (this.Enabled)
{
//BackColor for enabled textbox
this.BackColor = System.Drawing.SystemColors.Window;
}
else
{
//BackColor for disabled textbox
this.BackColor = System.Drawing.SystemColors.InactiveBorder;
}

//Set textbox style to userpaint
this.SetStyle(ControlStyles.UserPaint, !this.Enabled);

//Invalidate to paint the control
this.Invalidate();
}
}
}


Good luck,

Johnny J.





Rob said:
Ok, I will buy that... but there still appears to be no way to turn off
the "grey out attribute" when a textbox is not enabled....
Thanks...
 
Back
Top