Private strDate = New System.Windows.Forms.StatusBarPanel
Private StrCount = New System.Windows.Forms.StatusBarPanel
Private info = New System.Windows.Forms.StatusBarPanel
Private progress = New System.Windows.Forms.StatusBarPanel
Private StatusBar As New ProgressStatus ''状态条中加入进度条
Private Sub InitializeStatusBar()
info.Text = "Ready"
info.Width = 100
StrCount.AutoSize = System.Windows.Forms.StatusBarPanelAutoSize.Contents
StrCount.Alignment = HorizontalAlignment.Center
StrCount.Text = "完成 0 条记录"
progress.AutoSize = System.Windows.Forms.StatusBarPanelAutoSize.Spring
strDate.AutoSize = System.Windows.Forms.StatusBarPanelAutoSize.Contents
strDate.Text = System.DateTime.Now
strDate.Alignment = HorizontalAlignment.Right
With StatusBar
.Panels.Add(info)
.Panels.Add(progress)
.Panels.Add(StrCount)
.Panels.Add(strDate)
.ShowPanels = True
.setProgressBar = 1
.progressBar.Minimum = 0
.progressBar.Maximum = 100
End With
Me.Controls.Add(StatusBar)
End Sub
组件类:vb.net教程ProgressStatus.vb
Public Class ProgressStatus : Inherits StatusBar Public progressBar As New progressBar Private _progressBar As Integer = -1
Sub New()
progressBar.Hide()
Me.Controls.Add(progressBar)
End Sub
Public Property setProgressBar() As Integer
Get
Return _progressBar
End Get
Set(ByVal Value As Integer)
_progressBar = Value
Me.Panels(_progressBar).Style = StatusBarPanelStyle.OwnerDraw
End Set
End Property
Private Sub Reposition(ByVal sender As Object, ByVal sbdevent As System.Windows.Forms.StatusBarDrawItemEventArgs) Handles MyBase.DrawItem
progressBar.Location = New Point(sbdevent.Bounds.X, sbdevent.Bounds.Y)
progressBar.Size = New Size(sbdevent.Bounds.Width, sbdevent.Bounds.Height)
progressBar.Show()
End Sub
End Class