Click to See Complete Forum and Search --> : how to change Button Text Color


December 16th, 1999, 12:08 AM
How can i change the command button text color , run time also.

Chris Eastwood
December 16th, 1999, 05:22 AM
There are two ways of doing this -

1. Subclassing - lot's of code to write for the handling of painting the button text. I think you can find examples at either http://www.matthart.com or http://www.mvps.org/vbnet

2. Cheat !

You can place a checkbox on a form and set it's style to '1 - Graphical'. This then looks just like a button but you can change it's back and forecolor at runtime. All you need to be careful of is the click event where the button can stay 'clicked' - just paste this code into a form (FORM1) with a graphical check box (Check1) :


private Sub Check1_Click()
Check1.Value = vbUnchecked
Check1.ForeColor = RGB(Rnd(1) * 255, Rnd(1) * 255, Rnd(1) & 255)
Check1.BackColor = RGB(Rnd(1) * 255, Rnd(1) * 255, Rnd(1) & 255)
End Sub

private Sub Form_Load()
'
' Make sure Check1 has style set to '1-Graphical'
'
Check1.ForeColor = vbBlue
End Sub




- The only problem I can see doing it this way is that CheckBoxes can't have the 'default' or 'cancel' properties (although you could use keypreview to do the same things).



Chris Eastwood

CodeGuru - the website for developers
http://codeguru.developer.com/vb

Ravi Kiran
December 16th, 1999, 06:02 AM
BTW, i do precisely that soln of Chris.. use Check Boxes.. and it works quite fine for me

RK

December 16th, 1999, 08:01 AM
If you go to http://www.castlems.com/ammb.html they have a ActiveX control that you can put into your project that allows you to have alot of flexibility in designing all types of buttons etc.

I use this alot in my apps and have never had any problems.

Hope this helps
tcompe