我正在尝试用渐变颜色绘制我的winform应用程序,但是,发生了一些意外。 我发现有一些区域无法绘制,就像这张图: https://i.sstatic.net/MIVxXmpB.png 我已经尝试过多种方法,例如更改“高度”的值,如下图所示: https://i.sstatic.net/BIlIUGzu.png 或者在DrawRectangle方法中改变高度,如下图: [1]:https://i.sstatic.net/pB1zWZOf.png 有没有人可以来告诉我如何解决这个问题?
您没有发布代码,我不知道您是否尝试过以下操作:
覆盖
OnPaint
事件并使用事件参数的 Graphic
属性来使用 LinearGradientBrush
绘制背景。这是代码示例:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnLoad(e);
Graphics graphics = e.Graphics;
//the rectangle, the same size as our Form
Rectangle gradient_rectangle = new Rectangle(0, 0, Width, Height);
//define gradient's properties
Brush b = new LinearGradientBrush(gradient_rectangle, Color.White, Color.Black, 45f);
//apply gradient
graphics.FillRectangle(b, gradient_rectangle);
//this.BackColor = new LinearGradientBrush(new Point(0,0), new Point(this.Width, this.Height), Color.White, Color.Black);
}
}