.net - 表单背景颜色设置为淡色

标签 .net winforms colors background

如何设置附件中指定的表单的背景颜色?

enter image description here

最佳答案

一种方法是直接使用图像作为表单的 BackgroundImage

如果你想通过程序实现这一点(更灵活),你可以使用 OnPaintBackground 手动绘制窗体的背景:

protected override void OnPaintBackground(PaintEventArgs e)
{
    using (var brush = new LinearGradientBrush
               (DisplayRectangle, Color.Black, Color.DarkGray, LinearGradientMode.Vertical))
    {
        e.Graphics.FillRectangle(brush, DisplayRectangle);
    }
}

protected override void OnResize(EventArgs e)
{
    base.OnResize(e);
    Invalidate(); // Force repainting on resize
}

结果:

Gradient

关于.net - 表单背景颜色设置为淡色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8664973/

相关文章:

c# - 无法获得产品数量

c# - TreeNode.EndEdit 与 NodeLabelEditEventArgs.CancelEdit

c# - 在面板之间切换

ios - Sprite-Kit colorizeWithColor 没有将 Sprite 与正确的颜色混合

java - 如何更新点击处理程序,使其循环显示三种颜色 : red, 绿色和蓝色?

algorithm - 使用 "hue"混合模式混合两种非不透明颜色

c# - Windows Phone 应用程序不发送 Cookie,但在 Windows 8 应用程序中使用相同的代码发送 Cookie

c# - GridView 中 DropDownList 中的 Eval()

.net - WCF maxConnections 属性

C# Form.TransparencyKey 对不同颜色的工作方式不同,为什么?