Show an animated loading GIF image on a Windows Form (c#)
Hi friends,
Show an animated loading GIF image on a windows form with the help of backgroundWorker class in C#. My friends before start I want say that this is not the only way to attain this process. I think this is easy, so i post the code here.
Last week I got a problem to show the loading progress in the windows form. I wish to show the ajax loading image. For this I found a easy method "backgroundWorker".
BackgroundWorker class provides an easy way to run time-consuming operations on a background thread. Here i just explain to show the gif image with the help of BackgroundWorker class.
using System;
using System.Data;
using System.Drawing;
using System.Windows.Forms;
using System.Data.OleDb;
using System.Text;
namespace AirtelCustomerDts
{
public partial class Search : Form
{
DataTable DT;
public Search()
{
InitializeComponent();
ShowSearchTextbox();
}
private void btnSearch_Click(object sender, EventArgs e)
{
try
{
picLoder.Visible = true;
this.backgroundWorker1.RunWorkerAsync();
this.btnSearch.Enabled = false;
}
catch (Exception ex)
{
writelogfile.WriteFile("btnSearch_Click : ", ex.Message);
}
}
private void backgroundWorker1_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
{
DT = SearchDts().Tables[0];
}
private void backgroundWorker1_RunWorkerCompleted(object sender, System.ComponentModel.RunWorkerCompletedEventArgs e)
{
dgvSearchResult.DataSource = DT;
this.picLoder.Visible = false;
}
Hope the above code will help. He there is any doubt in backgroundWorker please feel free to ask me.