Welcome to WindowsClient.net | Sign in | Join

Here are some frequently asked questions about Windows Forms and their answers.

Windows Forms FAQs

How do I put controls, such as a ProgressBar, into a StatusBar?

You cannot place controls into a StatusBar control in the Designer. However, you can add any number of controls to the StatusBar programmatically through its Controls property. After adding the controls, set their Visible, Location, Bounds and other properties.

Here's a sample method that could be called in a form's constructor after InitializeComponent.

private void AddStatusBarControls( StatusBar sb )
{
  ProgressBar pb = new ProgressBar();
  sb.Controls.Add( pb );

  pb.Visible = true;
  pb.Bounds = new Rectangle( sb.Width/4, 4, sb.Width/2, sb.Height-8);
  pb.Anchor = AnchorStyles.Left | AnchorStyles.Right;
}

George Shepherd, Syncfusion, and Stuart Celarier, Fern Creek, 20 December 2004

Another approach is to use an owner-drawn StatusBar, as shown in this posting from the dotnet.discussion newsgroup at develop.com.

Jacob Grass (VB) and Jason Lavigne (C#)