Circular PB


SUBMITTED BY: Guest

DATE: July 31, 2014, 10:24 a.m.

FORMAT: C#

SIZE: 3.8 kB

HITS: 24940

  1. Class CircularPb
  2. Inherits Control
  3. Public Property Interval As Integer = 50
  4. Public Property StartAngle As Single = 30
  5. Public Property PenColor As Color = Color.FromArgb(58, 58, 58)
  6. Private Pen As New Pen(PenColor, 2)
  7. Private Timer As New Timers.Timer(Interval)
  8. Private Spokes As List(Of Spoke) = Nothing
  9. Private _InnerRadius As Integer = 4
  10. Private _OuterRadius As Integer = 8
  11. Private _AlphaStartValue As Integer = 255
  12. Private _SpokesCount As Integer = 12
  13. Private _AlphaChange As Integer = 0
  14. Private _AlphaLowerLimit As Integer = 15
  15. Private _AngleIncrement As Single = 0
  16. Public Sub New()
  17. Me.DoubleBuffered = True
  18. Me.Size = New Size(65, 65)
  19. Pen.EndCap = Drawing2D.LineCap.Round
  20. Pen.StartCap = Drawing2D.LineCap.Round
  21. AddHandler Timer.Elapsed, AddressOf OnTimerElapsed
  22. 'Start()
  23. End Sub
  24. Protected Overrides Sub OnSizeChanged(e As EventArgs)
  25. MyBase.OnSizeChanged(e)
  26. SpokesPoints()
  27. End Sub
  28. Protected Overrides Sub OnPaint(e As PaintEventArgs)
  29. MyBase.OnPaintBackground(e)
  30. Dim G As Graphics = e.Graphics
  31. G.Clear(BackColor)
  32. G.SmoothingMode = Drawing2D.SmoothingMode.HighQuality
  33. G.InterpolationMode = Drawing2D.InterpolationMode.HighQualityBicubic
  34. Dim alpha As Integer = _AlphaStartValue
  35. For i As Integer = 0 To _SpokesCount - 1
  36. Pen.Color = Color.FromArgb(alpha, PenColor)
  37. G.DrawLine(Pen, Spokes(i).StartPoint, Spokes(i).EndPoint)
  38. alpha -= _AlphaChange
  39. If alpha < _AlphaLowerLimit Then alpha = 255 - _AlphaChange
  40. Next
  41. End Sub
  42. Public Sub Start()
  43. Timer.Enabled = True
  44. End Sub
  45. Public Sub [Stop]()
  46. Timer.Enabled = False
  47. End Sub
  48. Private Sub OnTimerElapsed(sender As Object, e As Timers.ElapsedEventArgs)
  49. StartAngle += _AngleIncrement
  50. If StartAngle >= 360 Then StartAngle = 0
  51. _AlphaStartValue -= _AlphaChange
  52. If _AlphaStartValue < _AlphaLowerLimit Then _AlphaStartValue = 255 - _AlphaChange
  53. Invalidate()
  54. End Sub
  55. Private Structure Spoke
  56. Public StartPoint As PointF
  57. Public EndPoint As PointF
  58. Public Sub New(pt1 As PointF, pt2 As PointF)
  59. StartPoint = pt1
  60. EndPoint = pt2
  61. End Sub
  62. End Structure
  63. Private Sub SpokesPoints()
  64. Spokes = New List(Of Spoke)
  65. _AngleIncrement = (360 / CSng(_SpokesCount))
  66. _AlphaChange = CInt((255 - _AlphaLowerLimit) / _SpokesCount)
  67. Dim width As Integer = If((Me.Width < Me.Height), Me.Width, Me.Height)
  68. Dim _CentrePt = New PointF(Me.Width / 2, Me.Height / 2)
  69. Pen.Width = CInt(width / 15)
  70. If Pen.Width < 2 Then Pen.Width = 2
  71. _InnerRadius = CInt(width * 0.175F)
  72. _OuterRadius = CInt(width * 0.3125F)
  73. Dim angle As Single = 0
  74. For i As Integer = 0 To _SpokesCount - 1
  75. Dim pt1 As New PointF(_InnerRadius * CSng(Math.Cos((Math.PI / CDbl(180)) * angle)), _InnerRadius * CSng(Math.Sin((Math.PI / CDbl(180)) * angle)))
  76. Dim pt2 As New PointF(_OuterRadius * CSng(Math.Cos((Math.PI / CDbl(180)) * angle)), _OuterRadius * CSng(Math.Sin((Math.PI / CDbl(180)) * angle)))
  77. pt1.X += _CentrePt.X
  78. pt1.Y += _CentrePt.Y
  79. pt2.X += _CentrePt.X
  80. pt2.Y += _CentrePt.Y
  81. Spokes.Add(New Spoke(pt1, pt2))
  82. angle -= _AngleIncrement
  83. Next
  84. End Sub
  85. End Class

comments powered by Disqus