Click here to Skip to main content
15,917,060 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi,
i try to create global color scheme ,for all forms in the project. and instead of repeat the color , font ,...

ex:-
this.gridView2.Appearance.SelectedRow.BackColor = ((System.Drawing.Color)(resources.GetObject("gridView2.Appearance.SelectedRow.BackColor")));

i want to use :
this.gridView2.Appearance.SelectedRow.BackColor = projectColors.BackColor;


What I have tried:

i create a class to define all the used colors :
public static class ProjectColors
   {

       // gridcontrol



       // main color
       public static Color ChildFormBG = Color.FromArgb(248, 248, 248);

       public static Color PrimaryNormal = Color.FromArgb(48, 65, 75);
       public static Color PrimaryHover = Color.FromArgb(74, 97, 111);

       public static Color SecondryNormal = Color.FromArgb(19, 133, 214);
       public static Color SecondryHover = Color.FromArgb(60, 155, 222);


       // msgs
       public static Color ErrorNormal = Color.FromArgb(246, 86, 86);
       public static Color ErrorHover = Color.FromArgb(239, 49, 49);

       public static Color WarrningNormal = Color.FromArgb(255, 162, 52);
       public static Color WarrningHover = Color.FromArgb(248, 191, 51);

       public static Color SuccessNormal = Color.FromArgb(80, 184, 66);
       public static Color SuccessHover = Color.FromArgb(114, 195, 66);

       public static Color InfoNormal = Color.FromArgb(0, 174, 239);
       public static Color InfoHover = Color.FromArgb(0, 174, 239);

       public static Color NoteNormal = Color.FromArgb(248, 181, 51);
       public static Color NoteHover = Color.FromArgb(248, 181, 51);


       // form controls
       public static Color BorderNormal = Color.FromArgb(224, 224, 224);
       public static Color BorderFocused = Color.Silver;

       // buttons

   }


but whene i try the variable in the form.Designer.cs

this.gridView2.Appearance.SelectedRow.BackColor = projectColors.BackColor;


it changed automatically to :
this.gridView2.Appearance.SelectedRow.BackColor = ((System.Drawing.Color)(resources.GetObject("gridView2.Appearance.SelectedRow.BackColor")));


and some times the form can't loaded.

there are any other suggestions?
Posted
Updated 17-Mar-20 9:02am

You shouldn't touch the Form.Designer.cs file at all. It is auto-generated by the designer, and any customization you do in it is likely to be lost next time the designer saves it.

What you can do is create a method in Form.cs file, dealing with all your customizations; and call this method from the constructor, just after the call to InitializeComponent().
C#
public class MyForm : Form
{
   public MyForm()
   {
      InitializeComponent();
      ApplyTemplate();
   }

   private void ApplyTemplate()
   {
      this.gridView2.Appearance.SelectedRow.BackColor = ProjectColors.BackColor;
      // etc.
   }
}
 
Share this answer
 
Comments
Golden Basim 17-Mar-20 15:04pm    
thank you , i already did that but as you know i can't see the the design without run the program. so it's difficult and take long time.
Dave Kreskowiak 17-Mar-20 17:15pm    
There's no way around that.

Any changes you make to the form at all will cause the designer to regenerate the code in the form.designer.cs file and you will lose all your changes.
If you look closely, you will see the text:
C#
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
You should not be modifying the designer.cs file manually - and if you do, expect "this form could not be loaded" errors.

Instead, create a new form derived from Form:
C#
public partial class SkinnedForm : Form
   {
   ...
   }
And put your colour changes in the constructor of that class.
Then derive all your other forms from SkinnedForm instead of directly from the Form class.

That way, all the forms will contain everything from a Form, plus your colour code automatically.

Ideally, SkinnedForm would be an abstract class, but the VS designer can't cope with that well so just make sure you don't instantiate it yourself.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900