Advertisement
netrosly

Youtube Toggle

Dec 23rd, 2014
508
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.68 KB | None | 0 0
  1. Imports System.Drawing.Drawing2D
  2. Imports System.ComponentModel
  3.  
  4. <DefaultEvent("CheckedChanged")> Class Toggle : Inherits Panel
  5. Property FillColor As Color = Color.FromArgb(27, 132, 188)
  6. Public onoff As Boolean = False
  7. Public Event CheckedChanged(ByVal sender As Object)
  8. Public Sub New()
  9. Me.SetStyle(ControlStyles.DoubleBuffer Or ControlStyles.AllPaintingInWmPaint Or ControlStyles.UserPaint, True)
  10. DoubleBuffered = True
  11. Me.Size = New Size(44, 18)
  12. End Sub
  13.  
  14. <PropertyTab("Onoff")> _
  15. <DisplayName("Onoff")> _
  16. Public Property Icons() As Boolean
  17. Get
  18. Return onoff
  19. End Get
  20. Set(value As Boolean)
  21. onoff = value
  22. End Set
  23. End Property
  24. Friend NearSF As New StringFormat() With {.Alignment = StringAlignment.Near, .LineAlignment = StringAlignment.Near}
  25. Protected Overrides Sub OnPaint(e As PaintEventArgs)
  26. Dim bm As New Bitmap(Me.Width, Me.Height)
  27. Dim g As Graphics = Graphics.FromImage(bm)
  28. ' Me.Padding = New Padding(13, 39, 13, 24)
  29. ' Dim rect As New Rectangle(0, 0, Me.Width, (Me.Height - 35))
  30. ' Dim brush As New LinearGradientBrush(rect, Color.FromArgb(250, 250, 250), Color.FromArgb(206, 206, 206), 90.0!)
  31. 'Begin
  32. If onoff = True Then
  33. Dim Path As GraphicsPath = RoundRec(0, 0, Width - 2, Height - 2, 14)
  34. g.SmoothingMode = SmoothingMode.HighQuality
  35. g.FillPath(New SolidBrush(FillColor), Path)
  36. g.DrawPath(New Pen(FillColor), Path) '22, 122, 198
  37. g.DrawEllipse(New Pen(Color.FromArgb(255, 255, 255)), New Rectangle(Width - 17, Me.Height - 17, 14, 14))
  38. g.FillEllipse(New SolidBrush(Color.FromArgb(255, 255, 255)), New Rectangle(Width - 17, Me.Height - 17, 14, 14))
  39. g.DrawString("ΓΌ", New Font("Wingdings", 14), New SolidBrush(Color.FromArgb(255, 255, 255)), New Rectangle(0 + 7, Me.Height - 19, 14, 14), NearSF)
  40. Else
  41. Dim Path As GraphicsPath = RoundRec(0, 0, Width - 2, Height - 2, 14)
  42. g.SmoothingMode = SmoothingMode.HighQuality
  43. g.FillPath(New SolidBrush(Color.FromArgb(184, 184, 184)), Path)
  44. g.DrawPath(New Pen(Color.FromArgb(184, 184, 184)), Path)
  45. g.DrawEllipse(New Pen(Color.FromArgb(255, 255, 255)), New Rectangle(0 + 1, Me.Height - 17, 14, 14))
  46. g.FillEllipse(New SolidBrush(Color.FromArgb(255, 255, 255)), New Rectangle(0 + 1, Me.Height - 17, 14, 14))
  47. End If
  48. 'end
  49. e.Graphics.DrawImage(DirectCast(bm.Clone(), Bitmap), 0, 0)
  50. g.Dispose()
  51. bm.Dispose()
  52. MyBase.OnPaint(e)
  53. End Sub
  54. Dim x, y As Integer
  55. Private _Checked As Boolean = False
  56. #Region " Options"
  57.  
  58. <Category("Options")> _
  59. Public Property Checked As Boolean
  60. Get
  61. Return _Checked
  62. End Get
  63. Set(value As Boolean)
  64. _Checked = value
  65. End Set
  66. End Property
  67.  
  68. #End Region
  69. #Region "ThemeDraggable"
  70.  
  71. Private savePoint As New Point(0, 0)
  72. Private isDragging As Boolean = False
  73.  
  74. Protected Overrides Sub OnMouseDown(e As MouseEventArgs)
  75.  
  76. Dim clickRect2 As New Rectangle(0 + 1, Me.Height - 17, 14, 14)
  77. If onoff = False Then
  78. If clickRect2.Contains(New Point(e.X, e.Y)) Then
  79. onoff = True
  80. RaiseEvent CheckedChanged(Me)
  81. End If
  82. End If
  83. Dim clickRect3 As New Rectangle(Width - 17, Me.Height - 17, 14, 14)
  84. If onoff = True Then
  85. If clickRect3.Contains(New Point(e.X, e.Y)) Then
  86. onoff = False
  87. RaiseEvent CheckedChanged(Me)
  88. End If
  89. End If
  90. MyBase.OnMouseDown(e)
  91. End Sub
  92.  
  93. Protected Overrides Sub OnMouseUp(e As MouseEventArgs)
  94. isDragging = False
  95. MyBase.OnMouseUp(e)
  96. End Sub
  97.  
  98. Private mouseX As Integer
  99. Private mouseY As Integer
  100. Protected Overrides Sub OnMouseMove(e As MouseEventArgs)
  101. mouseX = e.X
  102. mouseY = e.Y
  103. MyBase.OnMouseMove(e)
  104. Invalidate()
  105. End Sub
  106. #End Region
  107. Private Sub Theme_Resize(sender As Object, e As EventArgs) Handles Me.Resize
  108. Me.Refresh()
  109. End Sub
  110. Public Function RoundRec(ByVal X As Integer, ByVal Y As Integer, _
  111. ByVal Width As Integer, ByVal Height As Integer, ByVal diameter As Integer) As System.Drawing.Drawing2D.GraphicsPath
  112.  
  113. ''the 'diameter' parameter changes the size of the rounded region
  114.  
  115. Dim graphics_path As New System.Drawing.Drawing2D.GraphicsPath
  116.  
  117. Dim BaseRect As New RectangleF(X, Y, Width, Height)
  118. Dim ArcRect As New RectangleF(BaseRect.Location, New SizeF(diameter, diameter))
  119.  
  120. 'top left Arc
  121. graphics_path.AddArc(ArcRect, 180, 90)
  122. graphics_path.AddLine(X + CInt(diameter / 2), _
  123. Y, X + Width - CInt(diameter / 2), Y)
  124.  
  125. ' top right arc
  126. ArcRect.X = BaseRect.Right - diameter
  127. graphics_path.AddArc(ArcRect, 270, 90)
  128. graphics_path.AddLine(X + Width, _
  129. Y + CInt(diameter / 2), X + Width, _
  130. Y + Height - CInt(diameter / 2))
  131.  
  132. ' bottom right arc
  133. ArcRect.Y = BaseRect.Bottom - diameter
  134. graphics_path.AddArc(ArcRect, 0, 90)
  135. graphics_path.AddLine(X + CInt(diameter / 2), _
  136. Y + Height, X + Width - CInt(diameter / 2), _
  137. Y + Height)
  138.  
  139. ' bottom left arc
  140. ArcRect.X = BaseRect.Left
  141. graphics_path.AddArc(ArcRect, 90, 90)
  142. graphics_path.AddLine(X, Y + CInt(diameter / 2), _
  143. X, Y + Height - CInt(diameter / 2))
  144.  
  145. Return graphics_path
  146.  
  147. End Function
  148.  
  149. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement