利用VB2005制作颜色渐变的进度条

来源:计算机等级考试    发布时间:2012-08-29    计算机等级考试视频    评论


  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

视频学习

我考网版权与免责声明

① 凡本网注明稿件来源为"原创"的所有文字、图片和音视频稿件,版权均属本网所有。任何媒体、网站或个人转载、链接转贴或以其他方式复制发表时必须注明"稿件来源:我考网",违者本网将依法追究责任;

② 本网部分稿件来源于网络,任何单位或个人认为我考网发布的内容可能涉嫌侵犯其合法权益,应该及时向我考网书面反馈,并提供身份证明、权属证明及详细侵权情况证明,我考网在收到上述法律文件后,将会尽快移除被控侵权内容。

最近更新

社区交流

考试问答