Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/279.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
以C#win形式创建维恩图_C#_Winforms_Graphics_Onpaint - Fatal编程技术网

以C#win形式创建维恩图

以C#win形式创建维恩图,c#,winforms,graphics,onpaint,C#,Winforms,Graphics,Onpaint,我需要在win form C#中创建一个维恩图。我一直在尝试使用Graphics.drawerlipse和FillElipse。但我不知道如何填写公共部分 我要做到这一点, 这是我的代码 private void panelControlVennDiagram_Paint(object sender, PaintEventArgs e) { Brush brushLeft = new SolidBrush(Color.Blue); Brush brushRight = new Soli

我需要在win form C#中创建一个维恩图。我一直在尝试使用Graphics.drawerlipse和FillElipse。但我不知道如何填写公共部分

我要做到这一点,

这是我的代码

private void panelControlVennDiagram_Paint(object sender, PaintEventArgs e)
{
  Brush brushLeft = new SolidBrush(Color.Blue);
  Brush brushRight = new SolidBrush(Color.LightPink);
  Brush brushCommon = new SolidBrush(Color.Purple);

  Pen pen = new Pen(brushLeft, 10);

  Rectangle leftVenn = new Rectangle(20, 50,100,100);
  Rectangle rightVenn = new Rectangle(90, 50, 100, 100);
  Rectangle commonVenn = new Rectangle(100, 120, 100, 100);

  Font stringFont = new Font("Times New Roman", 9);

  e.Graphics.DrawString("Left:" + leftValue, stringFont, brushLeft, 10,70);
  e.Graphics.DrawString("Right:" + rightValue, stringFont, brushRight, 90,70);
  e.Graphics.DrawString("Common:" + commonValue,stringFont, brushCommon, 100,70);

  // Fill ellipse on screen.
  e.Graphics.FillEllipse(brushLeft, leftVenn);
  e.Graphics.FillEllipse(brushRight, rightVenn);

  e.Graphics.DrawEllipse(Pens.White, leftVenn);
  e.Graphics.DrawEllipse(Pens.White, rightVenn);
}


我画了两个椭圆,需要有一个共同的部分不同的颜色。我不能使用任何图书馆。请帮助。

您可以添加
System.Drawing.Drawing2D要使用的命名空间
GraphicPath
。创建图形路径并获取相交区域

尝试以下代码:(为了测试目的,我已经注释了
DrawString

输出


您可以添加
System.Drawing.Drawing2D要使用的命名空间
GraphicPath
。创建图形路径并获取相交区域

尝试以下代码:(为了测试目的,我已经注释了
DrawString

输出


您可以使用半透明颜色,以便重叠部分的颜色是两个圆的实际合成颜色

Brush brushLeft = new SolidBrush(Color.FromArgb(50, Color.Blue));
Brush brushRight = new SolidBrush(Color.FromArgb(50, Color.Red));

您可以使用半透明颜色,以便重叠部分的颜色是两个圆的实际合成颜色

Brush brushLeft = new SolidBrush(Color.FromArgb(50, Color.Blue));
Brush brushRight = new SolidBrush(Color.FromArgb(50, Color.Red));

旁注:请处理所有画笔和画笔,或将它们转换为字段而不是局部变量以重复使用。旁注:请处理所有画笔和画笔,或将它们转换为字段而不是局部变量以重复使用。这很好。。。还有一个与此相关的问题,我还想处理venn图左/右和公共部分上的鼠标单击。如何保存鼠标位置?这很好用。。。还有一个与此相关的问题,我还想处理venn图左/右和公共部分上的鼠标单击。如何保存鼠标位置?有人能告诉我如何处理这些区域上的鼠标点击。。。左/右/普通?有人能告诉我如何处理这些区域的鼠标点击。。。左/右/普通?