SQL Server 2005 圆形进度条
显示一个旋转的进度条,与 SQL Server 2005 的忙碌指示器完全相同,无需任何代码。
- 下载源代码 - 11.3 Kb 已更新以包含双缓冲
- 下载演示项目 - 37.9 Kb
- 下载 C# 1.1 源代码 - 17 Kb 由 Olof Szymczak 转换
- 下载 C# 2.0 源代码 - 29.8 Kb 由 Olof Szymczak 转换
引言
在最初搜索 SQL Server 2005 中使用的动画作为 AVI 或 GIF 时,我偶然发现 Amr Aly Elsehemy 在 The Code Project 上的一篇优秀文章,这里。虽然代码很好,并且是我创建的内容的起点,但它并没有完全复制 Microsoft SQL Server 2005 的“忙碌”动画的外观和感觉。
该控件代码少于 220 行,我认为它非常紧凑,并且即使在我的应用程序中的其他线程繁忙时,它似乎也能很好地执行。
代码
我将进度条的每个“片段”存储在一个数组中,这使得稍后进行迭代变得容易。
Private segmentPaths(11) As Drawing2D.GraphicsPath
片段在 CalculateSegments
方法中初始化,该方法在控件初始化或调整大小后调用。此方法还会生成一个区域,该区域用于在绘制控件时将中心圆剪除。
'Create 12 segment pieces
For intCount As Integer = 0 To 11
secmentPaths(intCount) = New Drawing2D.GraphicsPath
'We subtract 90 so that the starting segment is at 12 o'clock
secmentPaths(intCount).AddPie(rctFull, (intCount * 30) - 90, 25)
Next
ProgressDisk_Paint
方法是所有实际工作发生的地方(不包括自动迭代)。我认为代码不言自明,尤其是注释 :-)
e.Graphics.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias
e.Graphics.ExcludeClip(innerBackgroundRegion)
For intCount As Integer = 0 To 11
If Me.Enabled Then
If intCount = m_TransitionSegment Then
'If this segment is the transistion segment, colour it differently
e.Graphics.FillPath(New SolidBrush(m_TransistionColour), _
segmentPaths(intCount))
ElseIf intCount < m_TransitionSegment Then
'This segment is behind the transistion segment
If m_BehindIsActive Then
'If behind the transistion should be active,
'colour it with the active colour
e.Graphics.FillPath(New SolidBrush(m_ActiveColour),_
segmentPaths(intCount))
Else
'If behind the transistion should be in-active,
'colour it with the in-active colour
e.Graphics.FillPath(New SolidBrush(m_InactiveColour), _
segmentPaths(intCount))
End If
Else
'This segment is ahead of the transistion segment
If m_BehindIsActive Then
'If behind the the transistion should be active,
'colour it with the in-active colour
e.Graphics.FillPath(New SolidBrush(m_InactiveColour),_
segmentPaths(intCount))
Else
'If behind the the transistion should be in-active,
'colour it with the active colour
e.Graphics.FillPath(New SolidBrush(m_ActiveColour),_
segmentPaths(intCount))
End If
End If
Else
'Draw all segments in in-active colour if not enabled
e.Graphics.FillPath(New SolidBrush(m_InactiveColour), _
segmentPaths(intCount))
End If
Next
唯一其他实际工作是由定时器增量完成的,默认情况下每 100 毫秒触发一次,但此项作为属性公开。If m_TransitionSegment = 11 Then
m_TransitionSegment = 0
m_BehindIsActive = Not m_BehindIsActive
ElseIf m_TransitionSegment = -1 Then
m_TransitionSegment = 0
Else
m_TransitionSegment += 1
End If
Invalidate()
m_BehindIsActive
变量决定了过渡片段(当前正在改变颜色的片段)之后的所有片段(逆时针方向)是否应使用活动颜色或非活动颜色着色,两者都是用户可定义的。