I want to load a small image into a WinForms control pictureBoxand then animate its movement to the other side of the form.
I uploaded the image and used the timer to move the image, but when I start it, the application just shows the end position pictureBoxand its image.
How can I show a smooth transition of the image to the final location?
Here is my code:
public partial class Form1 : Form
{
private int counter = 0;
void timer_Tick(object sender, EventArgs e)
{
counter++;
if (counter == 1)
{
pictureBox1.Show();
timer1.Stop();
counter = 0;
}
}
public Form1()
{
InitializeComponent();
timer1.Interval = 10;
timer1.Tick += new EventHandler(timer_Tick);
}
private void button1_Click(object sender, EventArgs e)
{
while(i<=100){
int x = pictureBox1.Location.X;
int y = pictureBox1.Location.Y;
pictureBox1.Location = new Point(x+25, y);
timer1.Start();
}
}
}
source
share