I\'ve been trying to smoothly animate some Windows Form location but I\'m having some issues if I want the speed to be variable. In other words, if I want to allow the user to s
Try this implementation of my prior suggestion (without accounting for FPS):
public partial class Form1 : Form
{
private bool go;
private int dx = 1;
public Form1()
{
InitializeComponent();
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
if (go)
{
this.Location = new Point(this.Location.X + dx, this.Location.Y);
if (Location.X < 10 || Location.X > 1200)
{
go = false;
dx = -dx;
}
else
{
this.Invalidate();
}
}
}
private void button1_Click(object sender, EventArgs e)
{
go = true;
this.Invalidate();
}
}
I think you will likely have to go outside of winforms to get higher FPS.