如何为 Windows 表单创建 select 深色主题的切换?那可以使整个背景变暗吗?在 C# 中

How to create a switch to select a dark theme for Windows Form? That can darken the whole background? in c#

如何为 Windows 论坛创建 select 深色主题的开关(就像 VPN 中的滑动开关)?那可以使整个背景变暗吗? 我想提供有关用户需求的选项,例如,他只是希望背景变暗还是希望文本框也变暗? 我在 google

上没有找到任何内容

这个问题的表述很奇怪,但我确实不明白你想要一个“外观菜单”之类的东西,用户可以只为每个控件类型 select 颜色(或仅 selected ).

这并不难,具体取决于您当前的技能水平。 对于提到的“滑动开关”(猜测像 IOS-toggle)试试这个简单的视频:https://www.youtube.com/watch?v=m7Iv6xfjnuw

现在进入主题切换部分: 定义一些您希望用户自定义的颜色变量

Color clrBackground = Color.FromArgb(32, 32, 32); 
Color clrFont = Color.White;
Color clrTbBack = Color.FromArgb(23, 23, 23);
...

现在创建一个 Methode 来更改颜色:

private void SwitchDesign()
{
    this.ForeColor = clrFont;
    this.BackColor = clrBackground;
    //Now for every special-control that does need an extra color / property to be set use something like this
    foreach (TextBox tb in this.Controls.OfType<TextBox>())
    {
       tb.BackColor = clrTbBack;
       //Maybe do more here...
    }
    //You could now add more controls in a similar fashion.
    this.Invalidate(); //Forces a re-draw of your controls / form
}

您现在唯一需要自己做的就是创建菜单来更改颜色,然后切换设计。简单的解决方案是使用 ColorDialog https://docs.microsoft.com/de-de/dotnet/api/system.windows.forms.colordialog?view=net-5.0

如果您的项目太大,这绝不是一个很好的解决方案,但对于中小型项目来说应该没问题。