0

In the top

public static GraphicsPath path;
PointF p;
double anglecounter;

In paint event

private void pictureBox1_Paint(object sender, PaintEventArgs e)
        {
            DrawRectangle(e, pictureBox1, 3, Color.Blue);

            anglecounter += 1;
            DrawLine(e.Graphics, anglecounter);
        }

DrawLine

private void DrawLine(Graphics g, double angle)
        {
            g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
            int r = pictureBox1.Size.Width / 2;
            int X1 = pictureBox1.Size.Width / 2;
            int Y1 = pictureBox1.Size.Height / 2;
            Point pStart = new Point(X1, Y1);
            int X2 = (int)(X1 + r * Math.Cos((double)angle / Math.PI / 180));
            int Y2 = (int)(Y1 + r * Math.Sin((double)angle / Math.PI / 180));
            Point pEnd = new Point(X2, Y2);
            g.DrawEllipse(new Pen(Color.Red, 2f), 0, 0, pictureBox1.Size.Width, pictureBox1.Size.Height);
            Rectangle rec = new Rectangle(0, 0, pictureBox1.Size.Width, pictureBox1.Size.Height);
            path = new GraphicsPath();
            path.AddPie(rec, (int)angle, -50);
            PathGradientBrush brush = new PathGradientBrush(path);
            brush.CenterPoint = pStart;
            brush.CenterColor = Color.LightGreen;
            brush.SurroundColors = new Color[] { Color.Empty };
            g.FillPath(brush, path);
            p = path.GetLastPoint();
        }

It's drawing the pie and the pie is moving in circles in the pictureBox1, the problem is the pie not moving in circles smooth enough, it seems that there is some stuttering or delay small one but there is.

The second problem is how to increase/decrease the rotation in circles speed ? if I change the paint event this line for example to 10

anglecounter += 10;

then it will rotate in circles faster but also in "jumps" of 10 each time. it's not really increasing the speed.

  • Notes here on floating point measures: [Rotate Point around pivot Point repeatedly](https://stackoverflow.com/a/50478311/7444103) -- Similar sample result: [Transparent Overlapping Circular Progress Bars (Custom Control)](https://stackoverflow.com/a/53379442/7444103) – Jimi Jan 21 '22 at 12:33
  • It is not obvious how the painting is paced. I used a Timer with an Interval of 31, whose Tick event handler increments the angle and calls pictureBox1.Invalidate(). Completely smooth on a PB as large as my screen allows, burns about 45% core on my pokey laptop. Use Task Manager to see what other processes may be stealing core away. – Hans Passant Jan 21 '22 at 13:04

0 Answers0