Click to See Complete Forum and Search --> : How to change the Forecolor of Command Button?


Ravi Kiran
March 18th, 1999, 01:48 AM
Hi Gurus,


I have a simple question!. How to change the ForeColor of a command button?


VB's 'Properties' window does not show 'ForeColor' for a command button.

It allows 'BackColor' to be changed and takes effect when 'Style' is set to 1.

What if i want to set 'ForeColor'?


But VB allows 'ForeColor' setting for Check Box & Option Button.

Right now i am faking using check box , with Style =1, it looks like a CommandButton and the first line in the Click event handler, would be to

set the value back to zero, to avoid 'pushed' look.


I dont want to use Sheredian controls or some such ActiveX controls just for the sake of color!, (unless unavoidable)


Do i need to use 'MaskColor' setting, to achieve the effect?

Interestingly, MSDN ( atleast the copy that i have, slightly old one, '98)

says 'ForeColor' property is available for command button also!


Can you please give me some hints?


Ravi Kiran

Chris Eastwood
March 18th, 1999, 02:55 AM
Hi


There's no easy way to do this in VB. When programming 'true' windows (ie. c/c++/delphi etc), you can create the Button Control with owner-drawn style which allows you to paint the command button in whatever way you want.


There is an excellent article at http://vbaccelerator.com that shows how to do this in VB with subclassing. You can get to the link from the codeguru site :


http://www.codeguru.com/vb/links/jump.cgi?ID=1678


Regards


Chris Eastwood


Codeguru - the website for developers

http://www.codeguru.com/vb




Drawing Buttons, Option Boxes and Check Boxes In Your Own Style

Crazy D
March 22nd, 1999, 09:23 PM
Hi


Yes you can do this in VB! (There's no need to subclass the button for this)


Use the SetTextColor API.


This is the declaration:

Private Declare Function SetTextColor Lib "gdi32" (ByVal hDC As Long, ByVal crColor As Long) As Long


And this is call itself:

Call SetTextColor(MyCommand1.hDC, [a long value containing the color, for instance vbBlack])

hmm ok vbBlack isn't a great example.. LOL vbRed will look fine.


Hope (I'm sure :-) this helps


Crazy D

Chris Eastwood
March 23rd, 1999, 03:14 AM
Hi


I couldn't get that to work - is this VB5/6 ?


You also need to get the Device Context from the command button (if using VB5 - don't know about VB6), ie.


Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long


Dim lDC As Long


lDC = GetDC(Command1.hwnd)


Ideas ?


Chris Eastwood

CodeGuru - the website for developers

http://www.codeguru.com/vb

Ravi Kiran
March 25th, 1999, 04:40 AM
Hi,


I too tried, and it doesn't work, atleast in VB 5.0


I tried with & w/o style set to 1; with & w/o Refresh, i.e call command1.Refresh after SetTextColor. Even call TextOut after setting color

all possibilities. But nothing works the way it is supposed to!


Ravi

Chris Eastwood
March 25th, 1999, 04:47 AM
Try the original link :


http://www.codeguru.com/vb/links/jump.cgi?ID=1678


The subclassing is very easy with Steve's subclassing DLL (or you can just compile the source of the DLL into your own app).


Regards


Chris Eastwood


Codeguru - the website for developers

http://www.codeguru.com/vb

Ravi Kiran
March 25th, 1999, 05:08 AM
Hi,


Ys. I have downloaded and am trying. It seems to require X-Times dll sSubtimer dll or something. I am on it right now..


Ravi