09-11-2000, 02:38 PM
I have read alot of information on this topic and have not found a good method for changing the text color of a command button. The best one used the color pallet in VB6 to change the color properties and any color can be selected however the problem is that at runtime it defaults back to windows colors.
Anyone know a work around to this ?
09-12-2000, 05:28 PM
<--- Check out the attachment.
It is pretty complicated but you don't even have to understand it to use it.
09-13-2000, 10:51 AM
There IS a way to change the text (forecolor) of a command button either at design time using the backcolor and forecolor properties or the color palette, or at runtime.
You can't do this with a standard command button though, because it doesn't have a 'forecolor' property. You have to use a Microsoft Forms 2.0 Object Library command button. These have no style property, they are graphical by default, but they DO have a forecolor property. If you set the forecolor at design time, it will stay at runtime and will not default to the system color, but you can also change the forecolor at runtime as you wish.
To add the Microsoft Forms 2.0 Object Library, go to the menu bar at the top of the screen and select 'Project'. Select 'Components' from the drop-down menu and in the components list, check 'Microsoft Forms 2.0 Object Library', apply and close.
The new components that are added to the toolbox on the left look similar to the standard ones that were already there, but they have different properties. The new command button will not be called 'command1' as usual when added to a form but 'commandbutton1' and will have no caption by default, you need to add the caption at design or runtime.
As an example of changing the colors at runtime, paste this code into the general declarations section of a form that contains a standard label- NOT a Forms 2.0 label - and a microsoft forms 2.0 object library command button.
Dim i, j
Private Sub CommandButton1_Click()
CommandButton1.BackColor = QBColor(i)
CommandButton1.ForeColor = QBColor(j)
If i <> 15 Then
i = i + 1
j = j - 1
Label1.Caption = "Keep clicking it!!"
Label1.Caption = "That's the lot - it's just a sample!!"
Private Sub Form_Load()
i = 0
j = 15
Label1.Alignment = 2
Label1.Font.Size = 12
Label1.Caption = "Hi - Click the button!!"
CommandButton1.Caption = "Button"
CommandButton1.Font.Size = 12
CommandButton1.Font.Bold = True
For colors, look up 'color constants', 'QBColor' and 'RGB' in the MSDN library. If you don't have it installed, you can access it online at
<A HREF="http://msdn.microsoft.com/library/default.asp" target="_new">http://msdn.microsoft.com/library/default.asp</A>