如何设置附件中指定的表单的背景颜色?
最佳答案
一种方法是直接使用图像作为表单的 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
}
结果:
关于.net - 表单背景颜色设置为淡色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8664973/