• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 182
  • 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
Restore individual SQL databases with ease

Veeam Explorer for Microsoft SQL Server delivers an easy-to-use, wizard-driven interface for restoring your databases from a backup. No expert SQL background required. Web interface provides a complete view of all available SQL databases to simplify the recovery of lost database

 
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

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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