Create a Status Bar control in Windows Application

Niladri.Biswas
Posted by in Windows Forms category on for Beginner level | Points: 250 | Views : 5172 red flag

This article will demonstrate as how to create and use Status Bar control in Windows Application


 Download source code for Create a 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.

Page copy protected against web site content infringement by Copyscape

About the Author

Niladri.Biswas
Full Name: Niladri Biswas
Member Level: Platinum
Member Status: Member
Member Since: 10/25/2010 11:04:24 AM
Country: India
Best Regards, Niladri Biswas
http://www.dotnetfunda.com
Technical Lead at HCL Technologies

Login to vote for this post.

Comments or Responses

Login to post response

Comment using Facebook(Author doesn't get notification)