Hi @Darryl Hoar , Welcome to Microsoft Q&A,
You can operate the interval moving image through the timer control. All you need to do is modify the corresponding speed.
Real-time values can also be modified in the tick event to achieve real-time effects by modifying the text of controls such as labels.
In the sample code below, I use a panel and a timer control to demonstrate.
using System;
using System.Drawing;
using System.Windows.Forms;
namespace xxx
public partial class Form1 : Form
{
private int linePosition = 0;
private const int lineWidth = 2;
private const int lineHeight = 20;
private const int moveSpeed = 5; //Adjust movement speed
public Form1()
{
InitializeComponent();
timer1.Interval = 50; //Adjust the timer interval
timer1.Start();
}
private void panel1_Paint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
Pen pen = new Pen(Color.Black, lineWidth);
// Draw a moving line
g.DrawLine(pen, linePosition, 0, linePosition, lineHeight);
}
private void timer1_Tick(object sender, EventArgs e)
{
//Update line position
linePosition += moveSpeed;
// Determine whether the right boundary of the Panel has been reached. If so, restart the movement.
if (linePosition > panel1.Width)
{
linePosition = 0;
}
// Refresh the Panel and trigger redrawing
panel1.Invalidate();
}
}
}
Best Regards,
Jiale
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.