Introducing Busy Indicator in Windows Forms | Syncfusion Blogs
Detailed Blog page Skeleton loader

We are excited to introduce the busy indicator drawing helper for Windows Forms. This busy indicator drawing helper has been implemented in our 2018 Volume 2 release. Usually, an animated GIF image cannot be shown in a Windows Forms control without using the picture box control or writing our own custom control. The busy indicator drawing helper helps you show animated GIF images in a control. The main advantage of this helper is that you can use it in any Windows Forms control, regardless of whether it is a Syncfusion control.

This blog explores how you can show animated GIF images using the busy indicator drawing helper in Windows Forms controls.

Getting started

Busy indicator is available in Syncfusion.Core.WinForms assembly. Refer to the control dependencies section to learn how to add an assembly reference to your application. BusyIndicator class provides the option to show an animated GIF image in the control. The Show method can be used to show the GIF image. By default, busy indicator shows the built-in GIF image. You can change the GIF image using the Image property or Show method.
Let’s see an example for showing the busy indicator in the button control. I’m going to show the busy indicator when a button is clicked, before an iteration gets started, and then hide it once the iteration gets completed.

 

public partial class Form1 : Form
{
    BusyIndicator busyIndicator = new BusyIndicator();
    ObservableCollection<int> sampleData = new ObservableCollection<int>();
    public Form1()
    {
        InitializeComponent();           
    }
    
    private void sfButton1_Click(object sender, EventArgs e)
    {
        this.sfButton1.Text = string.Empty;
        busyIndicator.Show(this.sfButton1);
        for (int i = 0; i <= 10000000; i++)
        {
            sampleData.Add(i);
        }
        busyIndicator.Hide();
        this.sfButton1.Text = "Get items";
        sampleData.Clear();
    }
}   

Showing busy indicator in a different location

By default, the GIF image will be shown at the center of the control. It’s easy to move the busy indicator to any location in the control, though. This can be done using the Location property or Show method.
public partial class Form1 : Form
{
    BusyIndicator busyIndicator = new BusyIndicator();
    ObservableCollection<int> sampleData = new ObservableCollection<int>();
    public Form1()
    {
        InitializeComponent();           
    }
    
    private void sfButton1_Click(object sender, EventArgs e)
    {
        this.sfButton1.Text = "Loading";
        busyIndicator.Show(this.sfButton1, new Point((this.sfButton1.Width / 2) + this.busyIndicator.Image.Width, (this.sfButton1.Height / 2) - this.busyIndicator.Image.Height / 2));
        for (int i = 0; i <= 10000000; i++)
        {
            sampleData.Add(i);
        }
        busyIndicator.Hide();
        this.sfButton1.Text = "Get items";
        sampleData.Clear();
    }
}

 

The sample can be downloaded from here.

Showing busy indicator in asynchronous mode

Busy indicator can be shown asynchronously in a control by handling the BackgroundWorker. The busy indicator can be shown when BackgroundWorker’s DoWork starts and can be hidden when BackgroundWorker’s RunWorkerCompleted is completed.
BackgroundWorker backgroundWorker = new BackgroundWorker();
BusyIndicator busyIndicator = new BusyIndicator();
ObservableCollection<int> sampleData = new ObservableCollection<int>();
public Form1()
{   
    InitializeComponent();           
    backgroundWorker.WorkerSupportsCancellation = true;
    backgroundWorker.DoWork += DoWork;
    backgroundWorker.RunWorkerCompleted += RunWorkerCompleted;
}

private void DoWork(object sender, DoWorkEventArgs e)
{
    this.sfButton1.Invoke(new Action(() => this.sfButton1.Text = string.Empty));
    busyIndicator.Show(this.sfButton1);
    for (int i = 0; i <= 10000000; i++)
    {
        sampleData.Add(i);
    }            
}

private void RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
    this.sfButton1.Text = "Get items";
    if (!backgroundWorker.IsBusy)
        backgroundWorker.CancelAsync();
    busyIndicator.Hide();
    sampleData.Clear();
}

private void sfButton1_Click(object sender, EventArgs e)
{
    backgroundWorker.RunWorkerAsync();
}
The sample can be downloaded from here.

Built-in busy indicator in data grid

Our new data grid has built-in busy indicator support for large data operations such as data loading, grouping, sorting, and filtering. Refer to this documentation to learn more about this support.

Summary

In this blog, we hope you enjoyed learning how to show the busy indicator in a Windows Forms control. You can also refer to this documentation to learn about additional options provided in the busy indicator. If you’re already a Syncfusion user, you can download the Windows Forms setup on Direct-Trac. If you’re not yet a Syncfusion user, you can download a free, 30-day trial on our website. Give us your feedback in the comments section below, our online forum, or a support ticket.

If you like this blog post, we think you’ll also like the following free e-books:

Be the first to get updates

Neelakandan Kannan

Meet the Author

Neelakandan Kannan

Neelakandan Kannan is a product manager at Syncfusion. He has been a .NET developer since 2014 with expertise in Flutter, WinForms and WPF.