Introduction
I create simple Gif/snipper tools. It's useful for most programs.
It is difficult to load and animate a picture .Gif within Windows form application. With this tool, you can easily do it just by giving image URL to this tool display animation. Also, you can select any .Gif photos to implement your spinner.
Background
After writing many programs, I found out that many people have problems with viewing Gif images, because Gif image cannot load in form thread. In C#, every object has its own thread and when we load .gif image in our project, the .gif image does not animate, then I create a simple tool for loading .gif image in forms.
Using the Code
That coding is simple, only add control ".dll" to your project. You need to right click on the toolbox, select "Choose Items.." and browse to the DLL containing the control or go to project menu > add reference and and browse to the DLL, then rebuild your project and then drag and drop control from toolbox on your form.
You can select your image with "LoadGIFImage
" in property window.
or use code:
Spinner.Start();
Spinner.Stop();
Spinner.LoadGIFImage =
How It Works
In C#, every object has its own thread and when we load .gif image in our project, the .gif image does not animate. For this reason, we use BackgroundWorker
to create a new thread for our .gif image.
public Image LoadGIFImage
{
get { return Loading_pb.Image; }
set { Loading_pb.Image = value; }
public void Start()
{
IsStart = true;
this.Visible = true;
var worker = new BackgroundWorker();
worker.DoWork += new DoWorkEventHandler(Loading);
worker.RunWorkerAsync();
}
public void Stop()
{
IsStart = false;
this.Visible = false;
}
void Loading(object sender, DoWorkEventArgs e)
{
while (IsStart)
{
this.Refresh();
}
}
History
- 27th June, 2015 - Initial release
Thank you
Thanks for reading and I hope you like the control.
If you make any modifications/bug fixes/enhancements to this control, please post in the comments section with your source snippets and/or ideas.