You have to define a variable double angle
then increment it by some amount every tot milliseconds
then just multiply the radius lenght by sin and cosine of than angle:
//using System.Timers;
public void DrawLine(PictureBox pb, Graphics g, float angle)
{
double radius = pictureBox1.ClientSize.Width / 2;
var center = new Point(radius, radius);
// remember that sin(0)=0 and cos(0)=1
// so if angle==0 the line is pointing up
// EDIT HERE: added center.x and center.y
var end = new Point(center.X + radius * Math.sin(angle), center.Y + radius * Math.cos(angle));
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
g.DrawLine(new Pen(Color.Red, 2f), center, end);
}
public static void rotate(Object source, ElapsedEventArgs e)
{
angle += <someAmountInRadiants>;
}
public static void SetTimer()
{
rotationTimer.Elapsed += rotate;
... // *for the uses of timers see below
}
double angle = 0;
Timer rotationTimer = new(<someAmountInMilliseconds>);
setTimer();
*Microsoft Wiki\Timer
To decide the speed of the rotation using total rotation time and steps you can just use Math.PI
:
# seconds needed to complete a full rotation
double rotTime = 2; # what you want
# how many times per second the line get mooved
double rotSteps = 360; # what you want
# amount of rotation that the line has to do, we can use this variable in rotate()
double rotAmount = Math.PI / rotSteps;
# every how much time increment the angle?
double rotDelay = rotTime / rotSteps;
# we use this in the timer, so we need to convert from seconds to milliseconds
rotDelay *= 1000;