Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to change the background color of a commandbutton

Activex

How to change the background color of a commandbutton

by  Mike Gagnon  Posted    (Edited  )
If you simply need a colored command button (VFP7.0 and down, since this feature was implemented in VFP8.0), use the Activex called Microsoft Forms2.0 commandbutton that ships with VFP, which has a background color property (If you are using it visually or programmatically, you cannot change the property on the Activex itself but the property need to be changed in the init of the form) . Here is an example how to use it, copy the following in a program and run it to see how it works:
Code:
Public oform1
oform1=createobject("form1")
oform1.AddObject("cmdbutton","cmdbutton")
oform1.Show
Return
Define Class form1 As Form
	DoCreate = .T.
	Caption = "Form1"
	Name = "Form1"
Enddefine
Define Class cmdButton As OleControl
	Procedure Init
	   With This
		.Object.BackColor = 255
		.Caption = "Click me!"
	   Endwith
      Endproc
OleClass = "forms.commandbutton.1"
Visible = .T.
Height =40
Top = 50
Left = 50
AutoSize = .T.
	Procedure Click
      	Messagebox("This is a red button")
      Endproc
Enddefine
[sub]This idea was inspired by David Frankenbach[/sub]
Mike Gagnon
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top