#Region "Imports"
Imports System.ComponentModel
#End Region
<ToolboxBitmap(GetType(ProgressStatusBar))> Public Class ProgressStatusBar : Inherits StatusBar
Private _progressBar As System.Windows.Forms.ProgressBar
Private _progressPosition As Integer = -1
#Region "Instantiation"
Public Sub New()
'instantiate the progress bar
_progressBar = New ProgressBar
'don't allow it to display yet
_progressBar.Hide()
'add to the controls collection of the status bar
Controls.Add(ProgressBar)
End Sub
#End Region
#Region "Property Procedures"
<Description("Gets or sets the position of the progress bar."), Category("Appearence")> _
Public Property ProgressPosition() As Integer
Get
Return _progressPosition
End Get
Set(ByVal Value As Integer)
'check to see if a valid value has been passed
If Value > PanelCount - 1 Then
Throw New ArgumentOutOfRangeException(ProgressPosition, Value, "Enter a value that is within the bounds of the panel count.")
Exit Property
End If
Dim panel As StatusBarPanel
_progressPosition = Value
'reset all the panels to text
Try
For Each panel In Panels
panel.Style = StatusBarPanelStyle.Text
Next
Finally
panel = Nothing
End Try
'set the property of the selected panel to owner drawn
Panels(_progressPosition).Style = StatusBarPanelStyle.OwnerDraw
End Set
End Property
<Description("Gets the progress bar object."), Browsable(False)> _
Public ReadOnly Property ProgressBar() As System.windows.forms.ProgressBar
Get
'returns the progress bar as an object allowing its properties to be set as normal
Return _progressBar
End Get
End Property
<Browsable(False), Description("Gets the number of panels in the status bar.")> _
Public ReadOnly Property PanelCount() As Integer
Get
Dim panel As StatusBarPanel
Dim count As Integer = 0
Try
For Each panel In Panels
count += 1
Next
Finally
panel = Nothing
End Try
Return count
End Get
End Property
#End Region
#Region "Private Procedures"
Private Sub Reposition(ByVal sender As Object, ByVal e As StatusBarDrawItemEventArgs) Handles MyBase.DrawItem
'set the location of the status bar to the x and y of the eventargs
_progressBar.Location = New Point(e.Bounds.X, e.Bounds.Y)
'set the size to fill the panel
_progressBar.Size = New Size(e.Bounds.Width, e.Bounds.Height)
'display the progress bar
_progressBar.Show()
End Sub
#End Region
End Class