Click here to Skip to main content
15,914,447 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I want to change the default disabled fore color of TextBox without overriding
C#
OnPaint()
method. Any Idea?

How can I handle WM_CTLCOLOREDIT and WM_CTLCOLORSTATIC message notifications in
C#
WndProc()
of my TextBox to change the forecolor ?.
Posted
Comments
ridoy 5-Dec-13 5:59am    
See:http://stackoverflow.com/questions/276179/how-to-change-the-font-color-of-a-disabled-textbox

Before you go to the trouble to dig into the Win API, you might consider the fact that if you set a Control's BackColor, and then disable it, it shows a slightly faded BackColor than it does if the Control is enabled.

May I suggest you try this experiment: create a set of four Buttons with BackColors like:

250, 200, 200 // pale red
200, 250, 200 // pale green
250, 250, 200 // pale yellow
200, 250, 250 // pale blue

Set their Enabled Property to 'false.

Copy them all, and paste, and put them side-by-side, so you have another, identical, set: set the copies' Enabled Property to 'true;

Now, run the Application and compare/observe the difference.

Is it possible that you could meet your needs for differentiating disabled Controls by Color by simply using the BackColor Property ?
 
Share this answer
 
This is just few more options as extension to the solution #1.

I guess you don't like grey forecolor for disabled textbox.

If that the case, you might try to experiment with ReadOnly property. It keeps text black.

Another possibility is to keep text box enabled and handle KeyPress event like shown below:
C#
private void textBox4_KeyPress(object sender, KeyPressEventArgs e)
{
    e.Handled = true;
}


And finally third option: overriding OnPaint. I know you ruled it out, but thee is noting wring with it at all if you want to enhance your text box with additional properties or non standard behavior.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900