如何在C#Winform中用颜色填充曲线区域?
我想用颜色(在我的例子中是黑色)在矩形中绘制曲线区域 我在OnPaint事件中尝试了很多事情FillPie,FillEllipse,但都做不到,我想这样画 我已经尝试了下面的代码。但这不是我想要的如何在C#Winform中用颜色填充曲线区域?,c#,winforms,C#,Winforms,我想用颜色(在我的例子中是黑色)在矩形中绘制曲线区域 我在OnPaint事件中尝试了很多事情FillPie,FillEllipse,但都做不到,我想这样画 我已经尝试了下面的代码。但这不是我想要的 protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); Graphics gr = e.Graphics; int x = 50; int y =
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
Graphics gr = e.Graphics;
int x = 50;
int y = 50;
int width = 100;
int height = 100;
Rectangle rect = new Rectangle(x, y, width / 2, height / 2);
gr.FillRectangle(Brushes.Black, rect);
gr.FillPie(Brushes.White, x, y, width, height, 180, 90);
using (Pen pen = new Pen(Color.Yellow, 1))
gr.DrawArc(pen, x, y, width, height, 180, 90);
}
这个代码是这样画的。我不想创建额外的矩形 我不能100%确定这是否是您想要的: 我通过创建一个具有指定矩形四分之一的
区域
来实现这一点。然后,我使用GraphicsPath
从中排除饼图。然后使用图形填充生成的曲线。使用黑色笔刷填充区域
:
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
Graphics gr = e.Graphics;
int x = 50;
int y = 50;
int width = 100;
int height = 100;
Rectangle rect = new Rectangle(x, y, width/ 2, height / 2);
Region r = new Region(rect);
GraphicsPath path = new GraphicsPath();
path.AddPie(x, y, width, height, 180, 90);
r.Exclude(path);
gr.FillRegion(Brushes.Black,r);
}