Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/311.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#Winform中用颜色填充曲线区域?_C#_Winforms - Fatal编程技术网

如何在C#Winform中用颜色填充曲线区域?

如何在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 =

我想用颜色(在我的例子中是黑色)在矩形中绘制曲线区域

我在OnPaint事件中尝试了很多事情FillPie,FillEllipse,但都做不到,我想这样画

我已经尝试了下面的代码。但这不是我想要的

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