0

我正在写维恩图,我在交叉路口有问题。

我画了圆圈,但我无法填充 3 个或更多圆圈的交点。

我用这段代码填充两个圆圈的交点

   Graphics g = this.CreateGraphics();
   GraphicsPath path = new GraphicsPath();
   Region region1 = new Region();

   Brush blue = new SolidBrush(Color.Blue);  
   Brush white=new SolidBrush(Color.White);
   Rectangle circle1 = new Rectangle(455, 200, 150, 150);
   Rectangle circle2 = new Rectangle(455, 275, 150, 150);
   g.FillEllipse(blue, circle1);
   g.FillEllipse(blue, circle2);

   path.AddEllipse(circle1);
   path.AddEllipse(circle2);
   region1.Intersect(path);
   g.FillRegion(white, region1);

我的意思是这样的

图片

4

1 回答 1

1

现在,您正试图将一个无限区域与一个包含两个圆圈的 GraphicsPath 对象相交。由于该区域一开始是无限的,因此 Intersect 方法将只返回您指定的 GraphicsPath 对象占用的区域。

要解决此问题,请通过将表示第一个圆圈的 GraphicsPath 传递给构造函数来创建您的区域。然后使用包含第二个圆的不同 GraphicsPath 调用 Intersect 函数。

于 2015-04-14T14:22:21.393 回答