This article will demonstrate as how to create and use Status Bar control in Windows Application
Introduction
Status bar control is no longer available in the VS2010 toolbox.It has been replaced by StatusStrip control.However, for backward compatibility , the StatusBar class is still available in Windows Forms.In this article, we will look into how to use this.
Straight to Experiment
Let us first write the code
protected StatusBar mainStatusBar = new StatusBar();
protected StatusBarPanel statusPanel = new StatusBarPanel();
private void CreateStatusBar()
{
statusPanel.BorderStyle = StatusBarPanelBorderStyle.Sunken;
statusPanel.Text = string.Empty;
statusPanel.AutoSize = StatusBarPanelAutoSize.Spring;
mainStatusBar.Panels.Add(statusPanel);
mainStatusBar.ShowPanels = true;
// Add StatusBar to Form controls
this.Controls.Add(mainStatusBar);
}
Status bar control is a collection of StatusBarPanel class.Each StatusBarPanel class can be use to display different information.
The "StatusBarPanelBorderStyle" has value values
- None:No border is displayed.
- Raised:The System.Windows.Forms.StatusBarPanel is displayed with a three-dimensional raised border.
- Sunken:The System.Windows.Forms.StatusBarPanel is displayed with a three-dimensional sunken border.
In the example, I am creating one panel and adding that to the StatusBar. Fianlly the Statusbasr is added to the main Form controls
Now create a button control and write the below code
private void btnProcess_Click(object sender, EventArgs e)
{
List<string> fruitList = GetFruitList();
foreach (string fruit in fruitList)
{
ShowMessageInStatusbar(fruit);
Thread.Sleep(100);
}
}
First we are preparing a fruit collection in the "GetFruitList()" method.Then Displaying the name of the same inside the status bar by using the "ShowMessageInStatusbar" function.
private void ShowMessageInStatusbar(string fruitName)
{
statusPanel.Text = "Processing " + fruitName;
}
References
StatusBar in C#
Conclusion
This article has demonstrated as how to create and use StatusBar in Windows forms.Thanks for reading.Zipped file is attached.