Before we talk about color settings, it’s important to know upfront where Visual FoxPro gets the default values for forms and form objects.
Have you ever wondered where the VFP IDE comes up with its default colors for forms (and other objects)? They come right from the Windows API.
According to the VFP Help File: “The color settings, or Themes, of the operating system set the default color settings for the BackColor and ForeColor properties.”
This explains why, on my machine, when I create a new form in Windows 7 the properties sheet contains the following (BackColor = 240,240,240):
The BackColor property depends completely on the current color scheme (theme) I’m using in Windows at design time. If I am set to Windows Classic in Windows 7, the BackColor is different. If I decide to punish myself and create a new form while the High Contrast (Black) theme is running, the default BackColor will be 0,0,0.
When I open this form in Windows XP, I get a different BackColor:
What this means is if I do not change the BackColor of a new form, even if I created the form in Windows 7 with an Aero theme, my form BackColor will match whatever theme I’m using in other versions of Windows (and Windows themes) at design time and runtime – without me having to do anything!
In short, Your Default BackColor = the Windows API System Color.
This is pretty powerful stuff. In Windows 7, I’ve created the form pictured below. I left the BackColor property as the Default. When I run it in Windows 7, I see this:
When I run the same form on Windows XP (with the Windows XP Blue Theme), I get this:
It’s different, but it’s exactly what Windows wants the BackColor to be, based on the theme.
When I change the XP theme to Windows Classic Spruce, I get this:
And once again, the BackColor matches the Windows theme at runtime. All without a single property change or a single line of code!
I wonder what happens when I make a change to the BackColor?
I flip back to my Windows 7 dev machine, change the BackColor to 192,192,192, save and run the form – and here’s what I see:
And running the same form on XP (again with the Blue Theme):
Whew! I’ve set my form BackColor to 192,192,192, and it looks relatively the same on my Windows 7 and Windows XP. So, I’m done, right?
Not quite. I changed my theme in Windows XP back to Spruce:
OK, I don’t like that. So, I’ll just jump back into VFP and change the color back to what Windows 7 said the default should be: 240,240,240.
Let’s see it in Windows 7:
So far, so good. Let’s see how it looks in Windows XP “Spruce”:
I expected my form BackColor to pick up the Windows theme again. But, it didn’t. Let’s take a look at the property sheet:
When a property is shown in Bold in the VFP Properties window, it’s not the Default – even if the value is the same as the Default value you expected.
So, how can we get it back to the way it was originally? Reset to Default. Right-click the property in the Properties window, and select “Reset to Default” from the context menu:
So, what’s the big tip for forms and form objects?
Don’t touch the default values for “color” properties if you want your forms (and form objects) to be consistent with Windows themes.
If you do change them, then later decide to go back to the “Default”, make sure you “Reset to Default”!
Just in case you need more evidence of just how ugly the form is when the BackColor is not set to the Default (i.e. Windows System Color), here’s the same form in High Contrast with the BackColor set to 192,192,192:
After a “Reset to Default”, the form looks like this:
As you can see from the previous images, the BackColor, ForeColor (in fact, all of the color properties) are tied to the Windows System Colors at runtime – but only if their values are set to their Default properties!