C# 应用程序广泛的色彩管理

发布于 2024-07-18 11:54:15 字数 157 浏览 6 评论 0原文

我正在编写一个大型 C# 应用程序。 要点是控件的颜色应该由应用程序的用户进行调整。 如果有任何解决方案可以覆盖(仅适用于此应用程序的上下文)System.Drawing.SystemColors,那么我就不必手动设置每个控件的值,那就太好了。 有人知道我的问题的解决方案就这么简单吗? 谢谢

im on to write a large C# Application.
The point is that the colors of the controls should be adjustable by the user of the application.
It would be really nice if there are any solution to override(only for the context of this application) the System.Drawing.SystemColors, so that i do not have to set the value of every single control by hand.
Do anybody know an solution for my problem which is that simple?
Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

墨落成白 2024-07-25 11:54:15

查看应用程序设置绑定。 不确定如何对所有控件执行此操作,但简单地通过控件树进行递归就足够了。

Look at Application Setting bindings. Not sure how you would do this for all controls, but simply recursing through the control tree should be sufficient.

岁月如刀 2024-07-25 11:54:15

我认为最好的方法是继承每个控件并设置其默认显示属性。 这将为您提供一个标准 WinForms 控件库,您可以轻松地自定义和重用它。 更多信息此处(在 VB 中,我找不到示例C#)。

I think your best approach would be to inherit each control and set its default display properties. This would give you a library of the standard WinForms controls that you could easily customize and re-use. More information here (in VB, I couldn't find examples in C#).

一指流沙 2024-07-25 11:54:15

您不需要覆盖系统默认值,但您可以定义自己的颜色。

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

1 = 红色
2 = 绿色
3 = 蓝色

You shouldn't need to override the system defaults but you are able to define your own colours.

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

1 = Red
2 = Green
3 = Blue

二智少女 2024-07-25 11:54:15

遗憾的是,无法仅针对您的应用程序修改 Windows 配色方案。

Winforms 可以更改窗体上所有控件的背景颜色等内容,但对于许多区域(例如按钮上的斜角颜色或窗口标题栏),您可能需要自己绘制控件。

Unfortunately it's not possible to modify the Windows colour scheme just for your application.

Winforms makes it possible to change things like the background colour for all controls on a form, but for many areas (such as the bevel colours on buttons, or window title bars), you'll probably need to resort to painting the control yourself.

毁虫ゝ 2024-07-25 11:54:15

我编写了下面的代码来执行类似的操作。 我对它不是特别满意,因为它需要对任何不寻常的控件进行专门处理,但它完成了工作。 我保留了一个 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);
    }
}

I wrote the code below to do something like this. I'm not particularly happy with it as it needs specialized handling for any controls that are out of the ordinary, but it did the job. I keep an instance of Painter around, and call Apply every time I create a form, passing the form as the argument. It recurses through all the child controls, altering their appearance

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);
    }
}
若水般的淡然安静女子 2024-07-25 11:54:15

花 1000 美元获取 DevExpress 的副本。 我们正在使用他们的框架编写一个大型应用程序,并且换肤能力非常好。

我知道这听起来不是最好的答案,但如果您正在寻找应用程序范围的换肤功能,第三方库可能是合适的。

Spend $1000 and get a copy of DevExpress. We're writing a large application using their framework, and the skinning ability is great.

I know this doesn't sound like the best answer, but if you're looking for application wide skinning ability, a third-party library may be appropriate.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文