Me.SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.UserPaint Or ControlStyles.DoubleBuffer Or ControlStyles.Opaque, True)
’更新风格
Me.UpdateStyles()
’新建颜色列表,加入红色,桔黄色,黄色,绿色,蓝绿色,蓝色,深蓝色,紫色
lstDefault = New List(Of Color)
lstDefault.Add(Color.Red)
lstDefault.Add(Color.Orange)
lstDefault.Add(Color.Yellow)
lstDefault.Add(Color.Green)
lstDefault.Add(Color.Cyan)
lstDefault.Add(Color.Blue)
lstDefault.Add(Color.Indigo)
lstDefault.Add(Color.Violet)
Value = Minimum
End Sub
’将两个颜色值混合成一个新的颜色。
Private Function MixColors(ByVal color1 As Color, ByVal color2 As Color) As Color
Return Color.FromArgb(CInt((CInt(color1.R) + CInt(color2.R)) / 2), CInt((CInt(color1.G) + CInt(color2.G)) / 2), CInt((CInt(color1.B) + CInt(color2.B)) / 2))
End Function
’建立颜色数组和画笔数组
Private Sub BuildColorList(ByRef lstAdd As List(Of Color))
Dim c As Color
Dim lstColors As New List(Of Color)
lstBrushes = New List(Of SolidBrush)
For Each c In lstAdd
lstColors.Add(c)
Next
Dim idx As Integer ’颜色数组索引
Dim cnt As Integer ’颜色数组长度
Dim sdc As Integer ’平滑度索引
’根据平衡度的不同创建颜色数组
For sdc = 0 To m_Smoothness Step 1
idx = 0
cnt = lstColors.Count - 1
While idx < cnt
lstColors.Insert(idx + 1, MixColors(lstColors(idx), lstColors(idx + 1)))
idx += 2
cnt += 1
End While
Next sdc
’根据颜色数组创建画笔数组
For Each c In lstColors
lstBrushes.Add(New SolidBrush(c))
Next
End Sub
’重载消息处理事件。
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
If m.Msg = &H14 Then
Return
End If
MyBase.WndProc(m)
End Sub
’重载窗口寸改变事件
Protected Overrides Sub OnResize(ByVal e As System.EventArgs)
MyBase.OnResize(e)
Me.Invalidate(False)
End Sub
’重载窗口绘制事件
Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
MyBase.OnPaint(e)
’绘制外框
e.Graphics.FillRectangle(New SolidBrush(Me.BackColor), Me.ClientRectangle)
’完成百分比
Dim percentComplete As Single = CSng((m_Value - m_Minimum) / (m_Maximum - m_Minimum))
If percentComplete <= 0.0F Then Exit Sub
If percentComplete > 1.0F Then percentComplete = 1.0F
Dim fullWidth As Single
’总宽度
fullWidth = CSng(Me.ClientRectangle.Width - BorderWidth)
’当前百分比所占用的宽度
Dim totalWidth As Single = fullWidth * percentComplete
’每个画笔填充颜色占用的宽度
Dim barWidth As Single
barWidth = fullWidth
barWidth /= CSng(lstBrushes.Count)
Dim height As Single
上一页 [1] [2]
责任编辑:小草