views:

360

answers:

3

I have a Winforms app in C# that calls calls a method asynchronously and uses a callback. I would like to display an animated gif to let the end user know that work is being done. I would like to have the animated gif hover over the center of the form.

How can I do this?

Update: Thanks. I guess the step I was missing was to use a Picture Box to hold the gif. The following seems to be doing the trick of showing the gif and like jmatthews3865 said below I can just set the visible property of the PictureBox to false to hide it.

private ShowAnimatedGif()
{
 PictureBox pb = new PictureBox();
 this.Controls.Add(pb);
 pb.Left = (this.Width / 2) - (pb.Width / 2);
 pb.Top = (this.Height / 2) - (pb.Height / 2);
 pb.Image = Resources.AnimatedGifHere;
 pb.Visible = true;
}
+2  A: 

Need some code to give an exact answer, but this is fairly trivial, insert the gif before you make the asynchronous call, then remove it in the callback.

Paul Creasey
A: 

See http://stackoverflow.com/questions/1929497/loading-gif-in-mvc

martinr
Apologies - this is not relevant to WinForms.
martinr
+2  A: 

in your form, simply include the image with it's visible property set to false.

from the event which calls the long running async process (button1_click etc.), set the images visibility property to true. event fires, image appears, async process runs and your ui thread should still be responsive.

in your callback event set the images visible property to false to indicate that the process is complete.