Animation in Winform

R

Rick

I have a form with a button control. When button is clicked; it run a process
which take a bit of time to complete the process.

When this button is clicked; I want to animate an image on the screen while
this process is in progerss. It is the same as displaying a progress bar butI
want to display animated image.
How do I do it in vs2005? My code is similiar to the following:

public partial class Form1 : Form
{
private Bitmap img;
private string sFilename = "C:\\MyGif.gif";
PictureBox imgPhoto = new PictureBox();

public Form1()
{
InitializeComponent();

img = new Bitmap(sFilename);
}

private void button1_Click(object sender, EventArgs e)
{
ProgressAnimation();
MyLongRunningProcess()

}

private void MyLongRunningProcess()
{
Retrieve20MillionRecordsFromDatabase();
}

private void Retrieve20MillionRecordsFromDatabase()
{
DoThis();
DoThat();
---- etc.
---- etc.
}

private void ProgressAnimation()
{
imgPhoto.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
imgPhoto.Height = 30;
imgPhoto.Width = 100;
imgPhoto.Left = 10;
imgPhoto.Top = 20;
imgPhoto.BackColor = Color.Red;
Controls.Add(imgPhoto);
imgPhoto.Image = img;
}
}
 
I

Ignacio Machin ( .NET/ C# MVP )

I have a form with a button control. When button is clicked; it run a process
which take a bit of time to complete the process.

When this button is clicked; I want to animate an image on the screen while
this process is in progerss. It is the same as displaying a progress bar butI
want to display animated image.
How do I do it in vs2005? My code is similiar to the following:

Two things, you have to run the query in another thread. This will
free the UI thread to execute your animation.
With that said, all you need is decide how to do the animation. The
basic one is a ProgressBar but you can use a more refined nethod.
I did a search for c# windows form animated gif in google and found
several examples.

Remember taht when finished you need to indicate it to the UI thread
by using Control.Invoke
 
R

Rick

Could you please provide me some sample code?

Ignacio Machin ( .NET/ C# MVP ) said:
Two things, you have to run the query in another thread. This will
free the UI thread to execute your animation.
With that said, all you need is decide how to do the animation. The
basic one is a ProgressBar but you can use a more refined nethod.
I did a search for c# windows form animated gif in google and found
several examples.

Remember taht when finished you need to indicate it to the UI thread
by using Control.Invoke
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top