Link to home
Start Free TrialLog in
Avatar of saruman101
saruman101

asked on

Microsoft, Visual Studio 2005, How to apply colors on all Forms in C#

Hey whats up guys it's been a long time I have not posted.
Any way I have jump the C# band wagon recently and  I'm enjoying every minute of it.

Any how guys I have a simple question if I have two or more forms, but in one of my window forms
I have an option for the user to choose any color he/she may want, how can I apply it to every form available.

In other words if the users chooses let say "blue" I want the form he/she is in as well as the other form which are open to apply the same color.

So far I have been able to do this
////////////////////////////

  ColorDialog Colors = new ColorDialog();
            Colors.ShowDialog();
                     this.BackColor = Colors.Color;  //(this works well because it changes the color at the  
                                                                         current form)
         

    EAGMainMenu eag = new EAGMainMenu();  //Main form
             eag.BackColor = Colors.Color;  //but if I do this..nothing happens to the original form..


//////////////

as you can see the code is really simple and all I need to know is from the 2nd form apply the same color
chosen to the first form.

Is there an easy way, am I close to doing this or no.

Again the code only works if  for the current form it is in.

Thanks in advances guys.
Avatar of Dirk Haest
Dirk Haest
Flag of Belgium image

I think you should consider using a forms collection. Becaust then you can loop through your open forms and color them all the same.

http://support.microsoft.com/kb/815707
ASKER CERTIFIED SOLUTION
Avatar of ToFro
ToFro
Flag of Finland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You can use visual inheritance or have a base form class that you can apply the colors to in order for the inheriting forms to use.

Bob
Avatar of saruman101
saruman101

ASKER

Sorry for not answering quick enough. I was going to say this works perfectly for me
//Try this:

foreach (Form openForm in Application.OpenForms)
{
    openForm.BackColor = Colors.Color;
}
//
If I were to do the same thing with the fonts how would I do it...or better yet do i need to do a for each loop and apply the font style to all the forms.. just as the color loop.

Would I Need to look through all the font styles and then apply...or am I lost here.

please post a small example similar to the code I did for the back ground color.
I will add an extra 75 points for this.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
// The same thing, but with Font

FontFamily family = new FontFamily("Arial");
float fontSize = 12.5F;

foreach (Form openForm in Application.OpenForms)
{
    openForm.Font = new Font(family, fontSize);
}
I would also look into Visual Inheritance like TheLearnedOne mentioned.

Going through all forms in Application.OpenForms is kind of the quick and dirty way. Note that it will only change the font for controls that use the font of the form. If you have a textbox for which you have set the font seperately, it will not be changed by the loop.