Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I fill in my half circles?

Tags:

c#

drawing

I am trying to fill in my two half circles. I want one side black and the other side white. What do I use?

Here is a snippet of my code:

    protected override void OnPaint(PaintEventArgs e)
    {
        base.OnPaint(e);
        Rectangle rect = new Rectangle(100, 100, 320, 320);
        e.Graphics.DrawArc(new Pen(new SolidBrush(Color.Black), 10), rect, 90, 180);
        e.Graphics.DrawArc(new Pen(new SolidBrush(Color.White), 10), rect, 270, 180);
    }
like image 899
Lebron Jamess Avatar asked Feb 09 '23 13:02

Lebron Jamess


1 Answers

What you expect to be called FillArc is actually called FillPie.

It takes the same parameters as DrawArc, so this will do:

e.Graphics.FillPie(Brushes.White, rect, 90, 180);
e.Graphics.FillPie(Brushes.Black, rect, 270, 180);

If you want to use the same rectangle you can 'deflate' it by 1/2 the pen width:

rect.Inflate(-5, -5);

Using

e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;

you get this:

enter image description here

like image 180
TaW Avatar answered Feb 20 '23 00:02

TaW