Imports System.ComponentModel Imports System.Windows.Forms.Design Public Class LabelWithBar Inherits Label Private mVal As Integer = 0 ' Current value Private mbarColor As Color = Color.Blue ' Color of bar Private mbarHeight As Integer = 0 Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs) Dim g As Graphics = e.Graphics Dim percent As Decimal = mVal / 100 Dim brush As SolidBrush = New SolidBrush(BarColor) Dim rect As Rectangle = e.ClipRectangle Dim height As Integer = mbarHeight rect.Width = rect.Width * percent If height = 0 Then height = rect.Height rect.Y = (rect.Height - height) / 2 rect.Height = height ' Draw bar g.FillRectangle(brush, rect) MyBase.OnPaint(e) End Sub _ Public Property Value() As Integer Get Return mVal End Get Set(ByVal Value As Integer) ' Make sure that the value does not stray outside the valid range. Select Case Value Case Is < 0 mVal = 0 Case Is > 100 mVal = 100 Case Else mVal = Value End Select ' Invalidate the control to get a repaint. Me.Invalidate() End Set End Property _ Public Property BarColor() As Color Get Return mbarColor End Get Set(ByVal Value As Color) mbarColor = Value ' Invalidate the control to get a repaint. Me.Invalidate() End Set End Property _ Public Property BarHeight() As Integer Get Return mbarHeight End Get Set(ByVal value As Integer) Select Case value Case Is > Me.Size.Height, Is < 0 mbarHeight = Me.Size.Height Case Else mbarHeight = value End Select ' Invalidate the control to get a repaint. Me.Invalidate() End Set End Property End Class _ _ Public Class ToolStripStatusLabelWithBar Inherits ToolStripStatusLabel Private mVal As Integer = 0 ' Current progress Private mbarColor As Color = Color.Blue ' Color of progress meter Private mbarHeight As Integer = 0 Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs) Dim g As Graphics = e.Graphics Dim percent As Decimal = mVal / 100 Dim brush As SolidBrush = New SolidBrush(BarColor) Dim rect As Rectangle = e.ClipRectangle rect.Width = rect.Width * percent Dim height As Integer = mbarHeight If height = 0 Then height = rect.Height rect.Y = (rect.Height - height) / 2 rect.Height = height ' Draw the progress meter. g.FillRectangle(brush, rect) MyBase.OnPaint(e) End Sub _ Public Property Value() As Integer Get Return mVal End Get Set(ByVal Value As Integer) ' Make sure that the value does not stray outside the valid range. Select Case Value Case Is < 0 mVal = 0 Case Is > 100 mVal = 100 Case Else mVal = Value End Select ' Invalidate the control to get a repaint. Me.Invalidate() End Set End Property _ Public Property BarColor() As Color Get Return mbarColor End Get Set(ByVal Value As Color) mbarColor = Value ' Invalidate the control to get a repaint. Me.Invalidate() End Set End Property _ Public Property BarHeight() As Integer Get Return mbarHeight End Get Set(ByVal value As Integer) Select Case value Case Is > Me.Size.Height, Is < 0 mbarHeight = Me.Size.Height Case Else mbarHeight = value End Select ' Invalidate the control to get a repaint. Me.Invalidate() End Set End Property End Class