如何填充C#填充矩形从下到上?

时间:2013-11-06 09:58:49

标签: c# system.drawing

我绘制了垂直矩形,但我想从下到上填充它。 这是我使用的代码

System.Drawing.Drawing2D.LinearGradientBrush linGrBrush = 
    new System.Drawing.Drawing2D.LinearGradientBrush(
           new Point(0, 12),
           new Point(0,2),
           Color.FromArgb(0, 0, 0, 0),
           Color.FromArgb(255, 190, 0, 0));

Pen pen = new Pen(linGrBrush);

e.Graphics.FillRectangle(linGrBrush,groupBox2.Width -50,10, 25,  x);

using (Pen Pen1 = new Pen(Color.BurlyWood, 4))
{
   e.Graphics.DrawRectangle(Pen1, groupBox2.Width -50,10, 25, 200);
}

x是颜色填充偏移,填充用于每2秒后填充矩形。

1 个答案:

答案 0 :(得分:0)

我认为您应该调整渐变的起点和终点:

System.Drawing.Drawing2D.LinearGradientBrush linGrBrush = 
         new System.Drawing.Drawing2D.LinearGradientBrush(
               new Point(0, 1),
               new Point(0,0),
               Color.FromArgb(0, 0, 0, 0),
               Color.FromArgb(255, 190, 0, 0));