日期:2014-05-17  浏览次数:20737 次

GDI绘图的一些问题
大侠们 小弟最近画了一个仪表盘 外观的圆圈就是DrawEllipse画出来的
现在希望圆圈的颜色分成3部分,黑色,绿色和红色,还要掌握好弧度,不知道大侠们有没有好的办法,小弟很感激啊!

------解决方案--------------------


Paint:

void Form1_Paint(object sender, PaintEventArgs e)
{
     Graphics g = e.Graphics;
     g.SmoothingMode = SmoothingMode.AntiAlias;

     GraphicsPath path = new GraphicsPath();
     path.Reset();
     path.AddArc(50, 50, 200, 200, 150, angle + 1);
     g.DrawPath(new Pen(Color.Red, 50f), path);

     path.Reset();
     path.AddArc(50, 50, 200, 200, 150 + angle, 240 - angle + 2);
     g.DrawPath(new Pen(Color.Gray, 50f), path);

     path.Reset();
     path.AddArc(50, 50, 200, 200, 30, 120 + 1);
     g.DrawPath(new Pen(Color.Green, 50f), path);

     float x = (float)Math.Cos((angle + 150) * Math.PI / 180) * 150 + 150;
     float y = (float)Math.Sin((angle + 150) * Math.PI / 180) * 150 + 150;
     path.Reset();
     path.AddLine(x, y, 150, 150);
     Pen pen = new Pen(Color.Blue, 10f);
     pen.StartCap = LineCap.ArrowAnchor;
     g.DrawPath(pen, path);
     pen.Dispose();

     path.Dispose();
}

timer:

private Timer timer;
int angle = 0;
void DrawArc()
{
    angle++;
    if (angle >= 240) angle = 0;
    this.Invalidate();
}
void timer_Tick(object sender, EventArgs e)
{
    DrawArc();
}

可以提取一个方法出来就方便用了