By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,812 Members | 1,288 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,812 IT Pros & Developers. It's quick & easy.

Setting Colors in Base Form to be used by Child Forms

P: n/a
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.

Jun 27 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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

"Demi" <d3*****@yahoo.com> wrote in message
news:11**********************@p79g2000cwp.googlegr oups.com...
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.

Jun 27 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.