1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
|
'version MonProgBar revu pour Alarm
Public Class MonProgBar
Inherits System.Windows.Forms.UserControl
Protected pMin As Integer
Protected pMax As Integer
Protected pValue As Integer
Protected pAlarmColor As Color
Private pAlarmPercent As Integer
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'UserControl overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
'
'MyProgBar
'
Me.Name = "MyProgBar"
Me.Size = New System.Drawing.Size(150, 48)
End Sub
#End Region
Public Property Min() As Integer
Get
Return pMin
End Get
Set(ByVal Value As Integer)
pMin = Value
End Set
End Property
Public Property Max() As Integer
Get
Return pMax
End Get
Set(ByVal Value As Integer)
pMax = Value
End Set
End Property
Public Property Value() As Integer
Get
Return pValue
End Get
Set(ByVal Value As Integer)
pValue = Value
Me.Invalidate(New Rectangle(0, 0, Me.Width, Me.Height))
Application.DoEvents()
End Set
End Property
Public Property AlarmColor() As Color
Get
Return pAlarmColor
End Get
Set(ByVal value As Color)
pAlarmColor = value
End Set
End Property
Public Property AlarmPercent() As Integer
Get
Return pAlarmPercent
End Get
Set(ByVal value As Integer)
pAlarmPercent = value
End Set
End Property
Public Sub StepOne()
Me.Value += 1
End Sub
Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
MyBase.OnPaint(e)
Drawbar(e)
End Sub
Protected Sub Drawbar(ByVal e As System.Windows.Forms.PaintEventArgs)
Dim Pct As Single = pValue / pMax * 100
'dessin ligne si Value < AlarmPercent avec AlarmColor
If Pct < Me.AlarmPercent Then
Dim Len As Single = pValue / pMax * Me.Width
Dim b As Brush = New System.Drawing.SolidBrush(Color.Red)
e.Graphics.DrawLine(New Pen(Me.ForeColor, Me.Height), 0, 0, Len, 0)
e.Graphics.DrawString(Pct.ToString & " % Done", Me.Font, b, 0, 0)
b.Dispose()
'dessin ligne si Value=AlarmPercent avec AlarmColor
Else
Dim lenPercent As Single = Me.AlarmPercent / pMax * Me.Width
Dim Len As Single = pValue / pMax * Me.Width
Dim b As Brush = New System.Drawing.SolidBrush(Color.Red)
'continue dessin pour Value < AlarmPercent
e.Graphics.DrawLine(New Pen(Me.ForeColor, Me.Height), 0, 0, Len, 0)
'la suite pour Value >= AlarmPercent
e.Graphics.DrawLine(New Pen(Me.AlarmColor, Me.Height), lenPercent, 0, Len, 0)
e.Graphics.DrawString(Pct.ToString & " % Done", Me.Font, b, 0, 0)
b.Dispose()
End If
End Sub
End Class |
Partager