I had a task to move an element(Button, Label...) around a panel within Winforms with C#.
I solved it like this, it works:
private void button1_Click(object sender, EventArgs e)
{
// System.Threading.Thread.Sleep(100 - auto.Geschwindigkeit);
for (int i = 0; i < panel1.Width; i++)
{
label1.Location = new Point(i, label1.Location.Y);
label2.Location = new Point(i, label2.Location.Y);
System.Threading.Thread.Sleep(50);//speed
Application.DoEvents();
}
}
But is there another way to do this, for example when I want to programm a game and I have 10 Labels(which represent a driving car), I think this would be to overloaded to work with Threads, because the CPU goes higher and higher ?! "System.Threading.Thread.Sleep(50);" would be the speed of an element, I think I need something which is more performant ?!
Thank You