-
I can't figure it out. Please help me. I would like the user to be able to change the backcolor of all forms and controls (i.e., command buttons, labels, etc.) by selecting a color from the Common Dialog control (ShowColor). frmMain has a menu option to change the forms' backcolor and forecolor. How do implement this in code? I know how to do it on the same form, but how do I have it affect all forms and controls within the application????
-
Could be wrong
If you want to do this at run time...
(I could be wrong)
But I'd write a function that takes a form, and a color
as argument and
load the form (at start of app) (Don't Have to show it)
go thru all the controls on each of the forms and change the backcolor to the desired color
One note though:
For command buttons... You have to set the style to 'Graphical' before doing that
-
this might work
Code:
comondialog1.showcolor
Dim MyControl As Control
For Each MyControl In form1.Controls
MyControl.backcolor = commondialog1.color
Next
hope that helps...
-
You would need to loop through all Forms.
Code:
Dim frm As Form
Dim ctl As Control
For Each frm In Forms
For Each ctl In frm.Controls
If TypeOf ctl Is CommandButton Then ctl.BackColor = vbBlue
Next ctl
Next frm
-
But this method doesn't work for all controls (I know it doesn't work for CommandButtons).
I've found some code about changing commandbutton's back color at www.vbaccelerator.com (I don't know exact URL) and I think it can be modified to change back colors of other controls, too.
-
You can change the background color of a CommandButton but it won't show unless you set it's Style property to 1 - Graphical.
-
Success at last!!
Thanks to everyone who responded. You were all very helpful.