Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# fill polygon (triangle)

I have problem with draw two polygons. I want to fill two triangles, but one is greater than the second. I am using UserControl in winforms. Code:

Point[] DOWN = new Point[] {new Point(0, 0), new Point(10, 0), new Point(5, 5)};
Point[] UP = new Point[] { new Point(0, 15), new Point(10, 15), new Point(5, 10) };

protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            SolidBrush brush = new SolidBrush(Color.FromArgb(253, 198, 19));       
            e.Graphics.FillPolygon(brush, DOWN);
            e.Graphics.FillPolygon(brush, UP);
            brush.Dispose();
        }

This is result of fill polygons Where is problem?

like image 685
peter.novan Avatar asked Nov 01 '25 09:11

peter.novan


1 Answers

Try setting the PixelOffsetMode property:

e.Graphics.PixelOffsetMode = PixelOffsetMode.Half;
using (SolidBrush brush = new SolidBrush(Color.FromArgb(253, 198, 19))) {
  e.Graphics.FillPolygon(brush, DOWN);
  e.Graphics.FillPolygon(brush, UP);
}

Result:

enter image description here

like image 80
LarsTech Avatar answered Nov 02 '25 22:11

LarsTech



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!