VB.NET 进度条与状态条的使用

来源:互联网 发布:小米平板2windows 驱动 编辑:程序博客网 时间:2024/05/16 15:05
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
 
组件类: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 ObjectByVal 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


原创粉丝点击