how to change the font color of command button please help newbiee....

Dani AI

Generated

Short answer: the classic VB6 CommandButton does not expose a simple caption color property in its standard mode — the control’s caption color is controlled by Windows and the VB runtime, so you cannot just set ForeColor on a normal push button. This is why and were seeing no effect. See the classic VB reference for how VB treats ForeColor/BackColor and CommandButton behavior. (xxxmen.github.io)
Programming Microsoft Visual Basic 6.0

If you need true colored captions (and do not want to use an image), the supported approach is to make the button owner-drawn and draw the caption yourself: change the control to an owner-draw style and handle the draw messages the parent receives (WM_DRAWITEM / related messages). In some cases WM_CTLCOLORBTN is relevant, but push buttons usually require owner-draw handling for full control of text color and appearance. Owner-draw gives complete control but requires subclassing/handling draw states (normal/pressed/disabled/focus) and careful GDI management. For references and examples of owner-drawn button techniques see the Win32 docs and owner-draw examples. (learn.microsoft.com)
WM_CTLCOLORBTN - Microsoft Docs · WM_DRAWITEM - Microsoft Docs · Owner Draw Button Helper Class (examples)

For most practical purposes the tradeoffs are: use the simple image-based approach (the suggestions from and ) or buy/use a custom/third-party button control; or move to VB.NET / WinForms where ForeColor is a normal property on controls if you can port the UI. (learn.microsoft.com)
Control.ForeColor (WinForms) - Microsoft Docs

Troubleshooting note: owner-draw code must explicitly draw all visual states (disabled, pressed, focus) and free any GDI objects you create; otherwise you will see flicker, wrong colors, or resource leaks.

Recommended Answers

All 7 Replies

how to change the font color of command button please help newbiee....

Hi... this is only base on my Knowledge i dont Know if their something else solution with your Problem... Just go to the Properties window, find forecolor and choose your favorite color,but before that you must click the command button.. but honestly you can't apply a font color in command button..

Hi... this is only base on my Knowledge i dont Know if their something else solution with your Problem... Just go to the Properties window, find forecolor and choose your favorite color,but before that you must click the command button.. but honestly you can't apply a font color in command button..

thankz for the suggestion i do that before but it doesn't affect my button.. is there any solution??

I guess you are talking about vb6.
I am using vb6 since past 1 yr and I learned that there is no such way (using vb) to change button font color.
Initially when i was newbie I also had that thought of changing the color and I approached me professors and few internet sources. But nothing helped me.
In short you cannot change button font color using vb.
(I will be very thankful if anyone really prove me wrong! Because I also want to change the color of button font)

Easiest workaround would be to to make a image with required text and color. It won't take much time. set button's picture property to that picture and style to 2-graphical

Just change the style property to graphical.

Yeah, that is one of the unfortuanate things about the command button is that they did not expose the fontcolor or forecolor for the control, but you can get around this (as mentioned above) by setting the style property to graphical at design time. Then you could use a picture box of the appropriate size with autoredraw set to true. Set its forecolor to the color you want then use Picture1.Print "Your Caption". After that set command1.picture = picture1.image. However, to get it to look right, you will have to set the currentx and currenty properties of the picture box before you print your caption.


Good Luck

gud day guyz.. thankz to all your response i will try all the opinions you suggest..i am very luck that u appreciate my post..thankz to all,,
it help me a lot ...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.