开发者

c# fill everything but GraphicsPath

开发者 https://www.devze.com 2022-12-14 06:51 出处:网络
I have some code that looks like that: GraphicsPath p = new GraphicsPath(); // Add some elements to p ...

I have some code that looks like that:

GraphicsPath p = new GraphicsPath();
// Add some elements to p ...
// ...

g.FillPath(bgBrush, p);
// where g : Graphics and bgBrush : Brush

Which resul开发者_运维问答ts in something that looks like this:

### |
  ##|
 ## |

How can I fill the exact complement of the path?

Desired output:

   #|
##  |
#  #|


I'm surprised no one answered so far - the solution is pretty simple. Just add a Rectangle to the path and everything inside gets reverted.

    protected override void OnPaint(PaintEventArgs e)
    {
        base.OnPaint(e);
        Graphics g = e.Graphics;
        g.Clear(BackColor);

        GraphicsPath p = new GraphicsPath();
        // add the desired path
        p.AddPie(100, 100, 100, 100, 0, 270);

        // add the rectangle to invert the inside
        p.AddRectangle(new Rectangle(50, 50, 200, 200));

        g.FillPath(Brushes.Black, p);
    }
0

精彩评论

暂无评论...
验证码 换一张
取 消