How to keep contents of a TextBox in black when the TextBox is disabled?
-
Hello When a TextBox is disabled the contents of that will all become greyish. How to avoid that, and keep the contents in black even when the TextBox is in disabled state? Thanks in advance
You should really stick to the standards, otherwise your UI will be a hell to use. Maybe you don't want to disable the edit box but set it read-only[^] ?
Cédric Moonen Software developer
Charting control [v2.0] OpenGL game tutorial in C++ -
Hello When a TextBox is disabled the contents of that will all become greyish. How to avoid that, and keep the contents in black even when the TextBox is in disabled state? Thanks in advance
Handle the WM_CTLCOLORSTATIC[^] message. This message is sent when a read-only or disables text box needs to be painted. The
wParam
parameter is the handle to the device context of the text box. You can select a black pen into this device context using SelectObject[^] which will make the text black. If you're using MFC override the OnCtlColor[^] function.«_Superman_» I love work. It gives me something to do between weekends.
Microsoft MVP (Visual C++) -
Handle the WM_CTLCOLORSTATIC[^] message. This message is sent when a read-only or disables text box needs to be painted. The
wParam
parameter is the handle to the device context of the text box. You can select a black pen into this device context using SelectObject[^] which will make the text black. If you're using MFC override the OnCtlColor[^] function.«_Superman_» I love work. It gives me something to do between weekends.
Microsoft MVP (Visual C++) -
Does Google not work in your neighborhood? He gave you the functions/messages to use, so how hard can it be to find samples of them?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
-
Hello When a TextBox is disabled the contents of that will all become greyish. How to avoid that, and keep the contents in black even when the TextBox is in disabled state? Thanks in advance
-
Instead of disabling the text box, just set it to read only (hine - ModifyStyle) - the text will stay black. Hope that helps.
Karl - WK5M PP-ASEL-IA (N43CS) PGP Key: 0xDB02E193 PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193
-
Handle the WM_CTLCOLORSTATIC[^] message. This message is sent when a read-only or disables text box needs to be painted. The
wParam
parameter is the handle to the device context of the text box. You can select a black pen into this device context using SelectObject[^] which will make the text black. If you're using MFC override the OnCtlColor[^] function.«_Superman_» I love work. It gives me something to do between weekends.
Microsoft MVP (Visual C++)Superman, I am using an Edit Control. I tried using the WM_CTLCOLORSTATIC message and added the, SetBkCOlor and SetTextColor function. But this is not working Is it due to the fact that am using Edit Control? I also tried using SelectObject and passed a BLACK brush, but that also doesn't seem to work As soon as the Edit Control is disabled, the text in Edit Control becomes grayish.
-
Superman, I am using an Edit Control. I tried using the WM_CTLCOLORSTATIC message and added the, SetBkCOlor and SetTextColor function. But this is not working Is it due to the fact that am using Edit Control? I also tried using SelectObject and passed a BLACK brush, but that also doesn't seem to work As soon as the Edit Control is disabled, the text in Edit Control becomes grayish.
You have to use
SelectObject
and pass in aBLACK
pen, not a brush.«_Superman_» I love work. It gives me something to do between weekends.
Microsoft MVP (Visual C++) -
You have to use
SelectObject
and pass in aBLACK
pen, not a brush.«_Superman_» I love work. It gives me something to do between weekends.
Microsoft MVP (Visual C++)Inside WM_CTLCOLORSTATIC, i check whether lParam is equal to Edit Control handle, if thats TRUE then i CreatePen by passing RGB(0, 0, 0), the resultant PEN is then passed to SelectObject(HDC, PEN); But this is not working. Any idea why it's not? Do i need to "return" something for the WM_CTLCOLORSTATIC ? Like, GetStockObject or something?
-
Problem with setting to read only, is that it will let the user select the text using the mouse. Where as in disabled mode, it will not let any mouse selections. I tried using WM_CTLCOLORSTATIC but not able to make just the text BLACK
So what's wrong with letting the user select the text - they can't change it, and they may want to copy it and paste it in the clipboard or another app. (You can also disable the tab stop so they can't tab to the control but would have to use the mouse to select the text.
Karl - WK5M PP-ASEL-IA (N43CS) PGP Key: 0xDB02E193 PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193
-
Inside WM_CTLCOLORSTATIC, i check whether lParam is equal to Edit Control handle, if thats TRUE then i CreatePen by passing RGB(0, 0, 0), the resultant PEN is then passed to SelectObject(HDC, PEN); But this is not working. Any idea why it's not? Do i need to "return" something for the WM_CTLCOLORSTATIC ? Like, GetStockObject or something?
If your pen that you created is going out of scope when WM_CTLCOLORSTATIC returns then it will be destroyed and the control will be greyed. Watch your object lifetimes. If this does not help, then post some code.
You may be right I may be crazy -- Billy Joel -- Within you lies the power for good - Use it!