Extensive color management in C # applications

im to write a great c # application. The fact is that the colors of the controls must be customizable by the application user. It would be great if there was any solution to override (for the context of this application only) System.Drawing.SystemColors, so I do not need to set the value of each individual control manually. Does anyone know a solution to my problem that is so simple? Thanks

+2
source share
6 answers

Look at application bindings. I'm not sure how you will do this for all controls, but just recursing through the control tree is enough.

+1
source

, , . WinForms, . ( VB #).

+1

, .

Color NastyColour = Color.FromArgb(1, 2, 3);

1 = 2 = 3 =

0

, Windows .

Winforms , , ( ) , , .

0

, - . , , , . Painter Apply , , . ,

public class Painter
{
    Color foreColor;
    Color backColor;
    Color altBackColor;
    Color buttonColor;
    Font font;

    public Painter(Color foreColor, Color backColor, Color altBackColor, Color buttonColor, Font font)
    {
        this.foreColor=foreColor;
        this.backColor=backColor;
        this.altBackColor=altBackColor;
        this.buttonColor=buttonColor;
        this.font=font;
    }    

    public void Apply(Control c)
    {
        if(c==null)
            return;

        c.ForeColor = foreColor;

        c.BackColor = (c is Button ) ? buttonColor
                                     : backColor;

        if (c is DataGridView)
        {
            var dgv = (DataGridView) c;
            dgv.BackgroundColor = BackColor;
            dgv.AlternatingRowsDefaultCellStyle.BackColor = altBackColor;
            dgv.ColumnHeadersDefaultCellStyle.BackColor = buttonColor;
        }

        c.Font = font;

        foreach(Control child in c.Controls)
            Apply(child);
    }
}
0

$1000 DevExpress. , , .

, , , .

-1

All Articles