代码之家  ›  专栏  ›  技术社区  ›  Dark Star1

如何使用形状定义剪裁区域?

  •  0
  • Dark Star1  · 技术社区  · 17 年前

    我仍然在模拟雷达(或尝试),通过反复试验,在我的图片盒背景上画了一个饼,大致覆盖了我想要画的目标区域。现在我试着把那个区域作为我的剪辑区域。我如何做到这一点?我没有遇到任何能清楚解释这一点的东西。我有以下代码:

    void OnPaintRadar(Object sender, PaintEventArgs e)
    {
        Graphics g = e.Graphics;
        Rectangle radar_rect = new Rectangle(myRadarBox.Left + 90, myRadarBox.Left + 18, myRadarBox.Width - 200, myRadarBox.Height + 200);
        using (Pen drw_pen = new Pen(Color.White, 1) )
        {
            g.DrawPie(drw_pen,radar_rect, 180, 180);
        }
    }
    

    我现在要做的是做一个我刚刚画了剪辑区域的饼。

    1 回复  |  直到 17 年前
        1
  •  1
  •   Thomas Levesque    17 年前

    不能使用在图形上绘制的饼图,需要为区域单独定义饼图:

    GraphicsPath gpath new GraphicsPath();
    gpath.AddPie(rect, startAngle, sweepAngle);
    gpath.CloseFigure();
    this.Region = new Region(gpath);