我从这个主题 GDI+ .NET 中发现了一个类似的问题:LinearGradientBrush 宽度超过 202 像素导致颜色环绕 但该解决方案对我不起作用。我也不能问那个话题。请看一下。这是我的代码:
public partial class Form1 : Form {
int ShadowThick = 10;
Color ShadowColor = Color.Gray;
int width;
int height;
public Form1() {
InitializeComponent();
width = this.Width - 100;
height = this.Height - 100;
}
private void Form1_Paint(object sender, PaintEventArgs e) {
//e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
GraphicsPath shadowPath = new GraphicsPath();
LinearGradientBrush shadowBrush = null;
// draw vertical shadow
shadowPath.AddArc(this.width - this.ShadowThick, this.ShadowThick, this.ShadowThick,
this.ShadowThick, 180, 180);
shadowPath.AddLine(this.width, this.ShadowThick * 2, this.width,
this.height - this.ShadowThick);
shadowPath.AddLine(this.width, this.height - this.ShadowThick,
this.width - this.ShadowThick, this.height - this.ShadowThick);
shadowPath.CloseFigure();
// declare the brush
shadowBrush = new LinearGradientBrush(PointF.Empty,
new PointF(this.ShadowThick + 1, 0), this.ShadowColor, Color.Transparent);
//shadowBrush = new LinearGradientBrush(PointF.Empty,
// new PointF(this.ShadowThick + 1, 0), this.ShadowColor, Color.Transparent);
//e.Graphics.DrawPath(Pens.Black, shadowPath);
e.Graphics.PixelOffsetMode = PixelOffsetMode.Half;
e.Graphics.FillPath(shadowBrush, shadowPath);
}
}
我希望从左到右从暗到亮,但请参阅:
我试图画一个阴影,我坚持这一点。