|
■No61610 (JRY さん) に返信
アニメーションがなくなってしまいますが、
SetStyleして自分で描画
Imports System.Windows.Forms.VisualStyles
Imports System.Drawing.Imaging
Public Class ProgressColor
Inherits ProgressBar
Public Sub New()
MyBase.New()
SetStyle(ControlStyles.UserPaint, True)
SetStyle(ControlStyles.AllPaintingInWmPaint, True)
SetStyle(ControlStyles.OptimizedDoubleBuffer, True)
End Sub
Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
Dim g = e.Graphics
Dim bmp = New Bitmap(Me.Width, Me.Height)
Dim g2 = Graphics.FromImage(bmp)
Dim rect1 = Me.DisplayRectangle
Dim intH6 = rect1.Height \ 6
Dim W1 = rect1.Width - 2
Dim W2 = W1 * Value \ Me.Maximum
Dim rect2 = New Rectangle(1, 1, W2, rect1.Height - 2)
Dim rect4 = New Rectangle(0, 0, rect1.Width - 1, rect1.Height - 1)
ProgressBarRenderer.DrawHorizontalBar(g2, rect1)
ProgressBarRenderer.DrawHorizontalChunks(g2, rect2)
Dim matrixElement As Single()() = _
{New Single() {1, 0, 0, 0, 0}, _
New Single() {1, 0, 0, 0, 0}, _
New Single() {0, 0, 1, 0, 0}, _
New Single() {0, 0, 0, 1, 0}, _
New Single() {0, 0, 0, 0, 1}}
Dim matrix As ColorMatrix = New ColorMatrix(matrixElement)
Dim attr As ImageAttributes = New ImageAttributes()
attr.SetColorMatrix(matrix)
g.DrawImage(bmp, _
New Rectangle(0, 0, W2 + 1, rect1.Height), _
0, 0, W2 + 1, rect1.Height, _
GraphicsUnit.Pixel, _
attr)
g.DrawImage(bmp, _
New Rectangle(W2 + 1, 0, W1 - W2 + 1, rect1.Height), _
W2 + 1, 0, W1 - W2 + 1, rect1.Height, _
GraphicsUnit.Pixel)
g2.Dispose()
bmp.Dispose()
End Sub
End Class
|