How to fill ellipses with different colors using GraphicsPath in WinForms?

694 views Asked by At

To solve flickering problem in WinForms when drawing multiple shapes, I decided to use GraphicsPathdo draw all shapes and then render using Graphics. It works perfectly; drawing never flickers even if a high number of shapes are drawn.

 panel.Paint += (sender, args) => {
      var graphicsPath = new GraphicsPath(FillMode.Winding);

      for (int i = 0; i < 10; i++)
      {
          graphicsPath.AddEllipse(0, i * 5, 20, 20);
      }

      args.Graphics.FillPath(new SolidBrush(Color.Red),  graphicsPath);

However, in this case all ellipses are the same color. Drawing every ellipse using graphics.FillPath() also causes flickering when shapes are redrawn (fot instance on Paint event).

Is there a way to draw each shape with a different color while continuing bulk drawing such as above one?

0

There are 0 answers