c# - 在 C# win Form 中创建维恩图

标签 c# winforms graphics onpaint

我需要在 win 窗体 C# 中创建维恩图。我一直在尝试使用 Graphics.DrawEllipse 和 FillElipse 来做到这一点。但是我不确定如何填写公共(public)部分。

我想实现这个,

enter image description here

这是我的代码,

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);

我正在绘制两个椭圆,公共(public)部分需要不同的颜色。我不能使用任何图书馆。请帮忙。

最佳答案

你可以使用半透明的颜色,这样重叠部分的颜色就是两个圆圈的实际合成颜色

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

enter image description here

关于c# - 在 C# win Form 中创建维恩图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25541036/

相关文章:

c# - 关于 OOPS 和 C# 中的编码风格

c# - CellFormatting 事件导致 .NET 4.5 应用程序上的渲染不稳定

c# - ASP.NET初学者问题: How to get rid of this error?

c# - 如何从 ContentView 访问 Xamarin Forms App 对象

winforms - 连接的 USB 设备的分类

c# - Windows窗体继承

opengl - 为什么 OpenGL 有一个远剪裁平面,用什么习语来处理这个问题?

algorithm - 如何在24 bpp显示器上最好地显示30+ bpp图形?

java - 为什么这两个弧重叠?

格式为 dd.MM.yyyy 的 c# SQL 查询错误