Click here to Skip to main content
6,292,426 members and growing! (10,088 online)
Email Password   helpLost your password?
Languages » VB.NET » HowTo     Intermediate License: The Code Project Open License (CPOL)

A class to put a ProgressBar or any control into a StatusBar

By Eric Marcon

How to simply display a control inside the StatusBar of your program.
VB.NET 1.0, .NET 1.1, Win2K, WinXP, Win2003VS.NET2003, Dev
Posted:28 Jan 2004
Updated:18 May 2005
Views:71,330
Bookmarked:66 times
Announcements
Loading...
 
Search    
Advanced Search
printPrint   Broken Article?Report       add Share
  Discuss Discuss   Recommend Article Email
28 votes for this article.
Popularity: 6.48 Rating: 4.48 out of 5

1
1 vote, 3.6%
2
2 votes, 7.1%
3
9 votes, 32.1%
4
16 votes, 57.1%
5

Introduction

It is not possible to directly put a ProgressBar or a button in a StatusBar in VB.NET. Solutions are available for C++ or VB 5 or 6.0. This is a way to do it in VB.NET. The previous version of this article, called StatusProgressBar only allowed using a ProgressBar. This new version extends the technique to any control.

Using the code

First, create a form with a StatusBar and a ProgressBar or any kind of control (tested with a button) you will put anywhere. You have to create at least a Panel in the StatusBar and make the Panels visible (.showpanels = True). The control put into the status bar will be called "child control".

Create an instance of StatusBarChild:

sbcProgressBar = New StatusBarChild(ProgressBar1, StatusBar1, 1)

The parameters are the ProgressBar (ProgressBar1), the StatusBar (StatusBar1) and the number of the statuspanel (0 for the first one on the left). An optional parameter is the margin between the statuspanel's edges and the ProgressBar. The ProgressBar is moved to the StatusBar when you create the StatusBarChild. You may put a button in the StatusBar the same way:

sbcButton= New StatusBarChild(Button1, StatusBar1, 1)

The StatusBarChild object's properties are the child control (.ChildObject), the StatusBar (.StatusBar), the panel number (.Panel) and the margin (.Margin). Its only method is .Resize, you should call it when the parent form is resized. See the demo for details.

How it works

The child control is declared as an object:

Public ChildControl As Control

The child control's parent is first changed:

 ChildControl.Parent = StatusBar

Then, it must be displayed in the proper panel. Since there is no property to get the Panel's actual width, an API call is necessary. SendMessage returns a RECT value containing the coordinates of the Panel.

Private Structure RECT
  Friend Left As Int32
  Friend Top As Int32
  Friend Right As Int32
  Friend Bottom As Int32
End Structure
Dim Rectangle As RECT
' Use the API to get the panel's display rectangle

SendMessage(StatusBar.Handle.ToInt32, SB_GETRECT, Panel, Rectangle)
' Resize

With ProgressBar
  .Left = Rectangle.Left + Margin
  .Top = Rectangle.Top + Margin
  .Height = Rectangle.Bottom - Rectangle.Top - 2 * Margin
  .Width = Rectangle.Right - Rectangle.Left - 2 * Margin
End With

You may use this technique to put any kind of control into a StatusBar, provided it has a .parent property.

The demo uses a button in the first panel, and a ProgressBar in the second one. Click the button to make the bar progress.

History

  • 1.1: Option Strict On allowed. See the first thread below.
  • 1.0: First public version. Did not allow Option Strict On.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Eric Marcon


Member

Occupation: Engineer
Location: France France

Other popular VB.NET articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 8 of 8 (Total in Forum: 8) (Refresh)FirstPrevNext
GeneralA really easy way PinmemberRyan Danforth17:54 10 Apr '08  
GeneralThanks PinmemberKeyPointAnalyzer6:19 13 Aug '07  
GeneralThanks PinmemberRanvA10:34 23 Apr '06  
GeneralAn alternative method PinmemberkaGyamfi2:17 29 Dec '05  
GeneralIn .Net v2.0 you will be able to do this. Pinmemberoshah3:19 16 May '05  
GeneralRe: In .Net v2.0 you will be able to do this. PinmemberEric Marcon3:12 17 May '05  
GeneralErrors when Option Strict is on Pinmemberwebbee11:26 9 Feb '05  
GeneralRe: Errors when Option Strict is on PinmemberEric Marcon8:57 11 Feb '05  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 18 May 2005
Editor: Smitha Vijayan
Copyright 2004 by Eric Marcon
Everything else Copyright © CodeProject, 1999-2009
Web12 | Advertise on the Code Project