Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > General > Command Button Text Color


Reply
 
Thread Tools Display Modes
  #1  
Old 09-11-2000, 02:38 PM
zoldy
Guest
 
Posts: n/a
Question Command Button Text Color


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 ?

Thanks

Reply With Quote
  #2  
Old 09-12-2000, 05:28 PM
Derek Stone
Guest
 
Posts: n/a
Default Re: Command Button Text Color

<--- Check out the attachment.
It is pretty complicated but you don't even have to understand it to use it.
Good Luck

-cl

Reply With Quote
  #3  
Old 09-13-2000, 10:51 AM
Sparkey
Guest
 
Posts: n/a
Default Re: Command Button Text Color

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!!"
Else
Label1.Caption = "That's the lot - it's just a sample!!"
End If
End Sub

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
End Sub

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>


Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->