Setting Colors in Base Form to be used by Child Forms

D

Demi

I want to be able to define standard colors in a base form, then have
child forms use those values instead of standard colors.

Ex in my base form I want to do this:

Color myColor = System.Drawing.SystemColors.Control;


Then in my child form in the designer, I want to be able to enter
"myColor" in the BackColor property.

This doesn't work since it's expecting an Int32. Is there a standard
way to externalize my color settings? This seems like it would be a
good technique to standardize color usage across many applications.
 
D

Dave Sexton

Hi Demi,

The BackColor property of a System.Windows.Forms.Control expects a
System.Drawing.Color structure not an Int32.

The BackColor property of a Control, in the PropertyGrid of the VS.NET Forms
designer, uses a custom Editor to allow the user to select a color. The
same display allows you to add your own colors by clicking the "Custom" tab
and right-mouse clicking in one of the blank white spaces at the bottom.

The colors you create using this dialog, however, are not 'named' and cannot
be accessed in code from any variable just by adding them to the dialog.
The colors cannot be set by referencing a variable in code. This method of
defining custom colors is only available to the user at design time, per
instance of VS.NET and custom colors aren't persisted between instances of
VS.NET.

Maybe you could write a VS.NET addin that would persist custom colors with
your project or solution.

If you want a more robust solution you should write a class to encaspulate
application-wide colors and styles to controls. You'll have to apply the
styles to controls at runtime like a stylesheet is applied to a webpage at
runtime.

HTH
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top