⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 progresscontrol.vb

📁 使用Access数据库演示的任务分配管理程序 一个使用ADO.NET基于Microsoft Access数据库演示的任务分配管理的程序
💻 VB
字号:
'
'Displays custom progress bar with bar on top and message on bottom.
'Draws on memory bitmap to avoid flashing.
'
Imports Microsoft.VisualBasic.CompilerServices
Imports System
Imports System.ComponentModel
Imports System.Data
Imports System.Diagnostics
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Runtime.CompilerServices
Imports System.Windows.Forms

Public Class ProgressControl
    Inherits UserControl

    ' Methods
    Public Sub New()
        AddHandler MyBase.Resize, New EventHandler(AddressOf Me.ProgressControl_Resize)
        AddHandler MyBase.Paint, New PaintEventHandler(AddressOf Me.ProgressControl_Paint)
        Me.m_ShowPercent = True
        Me.m_ProgressBackColor = Color.Khaki
        Me.m_ProgressBarColor = Color.SteelBlue
        Me.m_DataView = Nothing
        Me.m_DataMember = String.Empty
        Me.InitializeComponent()
        Me.SetStyle(ControlStyles.AllPaintingInWmPaint, True)
        Me.SetStyle(ControlStyles.UserPaint, True)
        Me.SetStyle(ControlStyles.DoubleBuffer, True)
    End Sub

    Private Sub DataBind()
        If Not ((Me.m_DataView Is Nothing) Or (Me.m_DataMember.Length = 0)) Then
            Me.m_Value = 0
            Try
                Dim num1 As Integer
                Dim view1 As DataRowView
                For Each view1 In Me.m_DataView
                    num1 = (num1 + Convert.ToInt32(RuntimeHelpers.GetObjectValue(view1.Item(Me.m_DataMember))))
                Next
                Me.m_Value = CInt(Math.Round(CDbl((CDbl(num1) / CDbl(Me.m_DataView.Count)))))
            Catch exception1 As Exception
                ProjectData.SetProjectError(exception1)
                ProjectData.ClearProjectError()
            End Try
            Me.Invalidate()
        End If
    End Sub

    Protected Overrides Sub Dispose(ByVal disposing As Boolean)
        If (disposing AndAlso (Not Me.components Is Nothing)) Then
            Me.components.Dispose()
        End If
        MyBase.Dispose(disposing)
    End Sub

    Private Sub DrawBar(ByVal g As Graphics, ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer, ByVal color As Color)
        Dim brush2 As New HatchBrush(HatchStyle.Percent50, color)
        Dim num1 As Integer = 3
        Do
            g.FillRectangle(brush2, (x + num1), (y + num1), width, height)
            num1 = (num1 + -1)
        Loop While (num1 >= 0)
        Dim rectangle1 As New Rectangle(x, y, width, height)
        Dim brush1 As New LinearGradientBrush(rectangle1, color, Me.GetHighlightColor(color), LinearGradientMode.Horizontal)
        g.FillRectangle(brush1, x, y, width, height)
    End Sub

    Private Sub DrawPercent(ByVal g As Graphics, ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer)
        Dim text1 As String = (Me.m_Value.ToString & "%")
        Dim size1 As Size = g.MeasureString(text1, Me.Font).ToSize
        g.DrawString(text1, Me.Font, New SolidBrush(Me.ForeColor), CSng((x + (CDbl((width - size1.Width)) / 2))), CSng((y + (CDbl((height - size1.Height)) / 2))))
    End Sub

    Private Sub DrawProgress(ByVal g As Graphics)
        If ((Me.Width <= 10) Or (Me.Height <= 10)) Then
            g.Clear(Me.BackColor)
        Else
            g.Clear(Me.BackColor)
            g.SmoothingMode = SmoothingMode.AntiAlias
            Dim num1 As Integer = (Me.Width - 20)
            Dim rectangle1 As New Rectangle((CInt(Math.Round(CDbl((CDbl((Me.Width - num1)) / 2)))) - 3), 7, num1, (Me.Height - 20))
            Me.DrawBar(g, rectangle1.Left, rectangle1.Top, rectangle1.Width, rectangle1.Height, Me.m_ProgressBackColor)
            If (Me.m_Value > 0) Then
                Dim num2 As Integer = CInt(Math.Round(CDbl((CDbl((rectangle1.Height * Me.m_Value)) / 100))))
                Me.DrawBar(g, rectangle1.Left, (rectangle1.Bottom - num2), rectangle1.Width, num2, Me.m_ProgressBarColor)
                If Me.ShowPercent Then
                    Me.DrawPercent(g, rectangle1.Left, (rectangle1.Bottom - num2), rectangle1.Width, num2)
                End If
            End If
        End If
    End Sub

    Private Function GetHighlightColor(ByVal color As Color) As Color
        Return Drawing.Color.FromArgb(255, Math.Min(255, CInt(Math.Round(CDbl((color.R * 1.5!))))), Math.Min(255, CInt(Math.Round(CDbl((color.G * 1.5!))))), Math.Min(255, CInt(Math.Round(CDbl((color.B * 1.5!))))))
    End Function

    <DebuggerStepThrough()> _
    Private Sub InitializeComponent()
        Me.Name = "ProgressControl"
        Dim size1 As New Size(112, 112)
        Me.Size = size1
    End Sub

    Private Sub OnDataChanged(ByVal sender As Object, ByVal args As ListChangedEventArgs)
        Me.DataBind()
    End Sub

    Private Sub ProgressControl_Paint(ByVal sender As Object, ByVal e As PaintEventArgs)
        Me.DrawProgress(e.Graphics)
    End Sub

    Private Sub ProgressControl_Resize(ByVal sender As Object, ByVal e As EventArgs)
        Me.Invalidate()
    End Sub


    ' Properties
    <Browsable(False), Description("Field in table used for binding.")> _
    Public WriteOnly Property DataMember() As String
        Set(ByVal Value As String)
            Me.m_DataMember = Value
            Me.DataBind()
        End Set
    End Property

    <Browsable(False), Description("Table used for data binding.")> _
    Public WriteOnly Property DataTable() As DataTable
        Set(ByVal Value As DataTable)
            Me.m_DataView = Value.DefaultView
            AddHandler Me.m_DataView.ListChanged, New ListChangedEventHandler(AddressOf Me.OnDataChanged)
            Me.DataBind()
        End Set
    End Property

    <DefaultValue("Khaki"), Description("Back color of progress bar."), Category("Appearance")> _
    Public Property ProgressBackColor() As Color
        Get
            Return Me.m_ProgressBackColor
        End Get
        Set(ByVal Value As Color)
            Me.m_ProgressBackColor = Value
            Me.Invalidate()
        End Set
    End Property

    <DefaultValue("SteelBlue"), Category("Appearance"), Description("Progress bar color.")> _
    Public Property ProgressBarColor() As Color
        Get
            Return Me.m_ProgressBarColor
        End Get
        Set(ByVal Value As Color)
            Me.m_ProgressBarColor = Value
            Me.Invalidate()
        End Set
    End Property

    <DefaultValue(False), Category("Appearance"), Description("Show item percent.")> _
    Public Property ShowPercent() As Boolean
        Get
            Return Me.m_ShowPercent
        End Get
        Set(ByVal Value As Boolean)
            Me.m_ShowPercent = Value
            Me.Invalidate()
        End Set
    End Property


    ' Fields
    Private Const BorderSize As Integer = 10
    Private components As IContainer
    Private m_DataMember As String
    Private m_DataView As DataView
    Private m_ProgressBackColor As Color
    Private m_ProgressBarColor As Color
    Private m_ShowPercent As Boolean
    Private m_Value As Integer
    Private Const ShadowSize As Integer = 3
End Class


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -