• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 184
  • Last Modified:

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.
0
saruman101
Asked:
saruman101
2 Solutions
 
DhaestCommented:
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
0
 
ToFroCommented:
Try this:

foreach (Form openForm in Application.OpenForms)
{
    openForm.BackColor = Colors.Color;
}
0
 
Bob LearnedCommented:
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
0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

 
saruman101Author Commented:
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.
0
 
DhaestCommented:
Like 'TheLearnedOne' already mentioned, you can also use Visual Inheritance.
See http://www.codeproject.com/dotnet/visualForm.asp
0
 
ToFroCommented:
// 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);
}
0
 
ToFroCommented:
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.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now