Advertisement
netrosly

Complex Trackbar

Dec 23rd, 2014
430
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.32 KB | None | 0 0
  1. Module DesignFunctions
  2. Function ToBrush(ByVal A As Integer, ByVal R As Integer, ByVal G As Integer, ByVal B As Integer) As Brush
  3. Return ToBrush(Color.FromArgb(A, R, G, B))
  4. End Function
  5. Function ToBrush(ByVal R As Integer, ByVal G As Integer, ByVal B As Integer) As Brush
  6. Return ToBrush(Color.FromArgb(R, G, B))
  7. End Function
  8. Function ToBrush(ByVal A As Integer, ByVal C As Color) As Brush
  9. Return ToBrush(Color.FromArgb(A, C))
  10. End Function
  11. Function ToBrush(ByVal Pen As Pen) As Brush
  12. Return ToBrush(Pen.Color)
  13. End Function
  14. Function ToBrush(ByVal Color As Color) As Brush
  15. Return New SolidBrush(Color)
  16. End Function
  17. Function ToPen(ByVal A As Integer, ByVal R As Integer, ByVal G As Integer, ByVal B As Integer) As Pen
  18. Return ToPen(Color.FromArgb(A, R, G, B))
  19. End Function
  20. Function ToPen(ByVal R As Integer, ByVal G As Integer, ByVal B As Integer) As Pen
  21. Return ToPen(Color.FromArgb(R, G, B))
  22. End Function
  23. Function ToPen(ByVal A As Integer, ByVal C As Color) As Pen
  24. Return ToPen(Color.FromArgb(A, C))
  25. End Function
  26. Function ToPen(ByVal Color As Color) As Pen
  27. Return ToPen(New SolidBrush(Color))
  28. End Function
  29. Function ToPen(ByVal Brush As SolidBrush) As Pen
  30. Return New Pen(Brush)
  31. End Function
  32.  
  33. Class CornerStyle
  34. Public TopLeft As Boolean
  35. Public TopRight As Boolean
  36. Public BottomLeft As Boolean
  37. Public BottomRight As Boolean
  38. End Class
  39.  
  40. Public Function AdvRect(ByVal Rectangle As Rectangle, ByVal CornerStyle As CornerStyle, ByVal Curve As Integer) As GraphicsPath
  41. AdvRect = New GraphicsPath()
  42. Dim ArcRectangleWidth As Integer = Curve * 2
  43.  
  44. If CornerStyle.TopLeft Then
  45. AdvRect.AddArc(New Rectangle(Rectangle.X, Rectangle.Y, ArcRectangleWidth, ArcRectangleWidth), -180, 90)
  46. Else
  47. AdvRect.AddLine(Rectangle.X, Rectangle.Y, Rectangle.X + ArcRectangleWidth, Rectangle.Y)
  48. End If
  49.  
  50. If CornerStyle.TopRight Then
  51. AdvRect.AddArc(New Rectangle(Rectangle.Width - ArcRectangleWidth + Rectangle.X, Rectangle.Y, ArcRectangleWidth, ArcRectangleWidth), -90, 90)
  52. Else
  53. AdvRect.AddLine(Rectangle.X + Rectangle.Width, Rectangle.Y, Rectangle.X + Rectangle.Width, Rectangle.Y + ArcRectangleWidth)
  54. End If
  55.  
  56. If CornerStyle.BottomRight Then
  57. AdvRect.AddArc(New Rectangle(Rectangle.Width - ArcRectangleWidth + Rectangle.X, Rectangle.Height - ArcRectangleWidth + Rectangle.Y, ArcRectangleWidth, ArcRectangleWidth), 0, 90)
  58. Else
  59. AdvRect.AddLine(Rectangle.X + Rectangle.Width, Rectangle.Y + Rectangle.Height, Rectangle.X + Rectangle.Width - ArcRectangleWidth, Rectangle.Y + Rectangle.Height)
  60. End If
  61.  
  62. If CornerStyle.BottomLeft Then
  63. AdvRect.AddArc(New Rectangle(Rectangle.X, Rectangle.Height - ArcRectangleWidth + Rectangle.Y, ArcRectangleWidth, ArcRectangleWidth), 90, 90)
  64. Else
  65. AdvRect.AddLine(Rectangle.X, Rectangle.Y + Rectangle.Height, Rectangle.X, Rectangle.Y + Rectangle.Height - ArcRectangleWidth)
  66. End If
  67.  
  68. AdvRect.CloseAllFigures()
  69.  
  70. Return AdvRect
  71. End Function
  72.  
  73. Public Function RoundRect(ByVal Rectangle As Rectangle, ByVal Curve As Integer) As GraphicsPath
  74. RoundRect = New GraphicsPath()
  75. Dim ArcRectangleWidth As Integer = Curve * 2
  76. RoundRect.AddArc(New Rectangle(Rectangle.X, Rectangle.Y, ArcRectangleWidth, ArcRectangleWidth), -180, 90)
  77. RoundRect.AddArc(New Rectangle(Rectangle.Width - ArcRectangleWidth + Rectangle.X, Rectangle.Y, ArcRectangleWidth, ArcRectangleWidth), -90, 90)
  78. RoundRect.AddArc(New Rectangle(Rectangle.Width - ArcRectangleWidth + Rectangle.X, Rectangle.Height - ArcRectangleWidth + Rectangle.Y, ArcRectangleWidth, ArcRectangleWidth), 0, 90)
  79. RoundRect.AddArc(New Rectangle(Rectangle.X, Rectangle.Height - ArcRectangleWidth + Rectangle.Y, ArcRectangleWidth, ArcRectangleWidth), 90, 90)
  80. RoundRect.AddLine(New Point(Rectangle.X, Rectangle.Height - ArcRectangleWidth + Rectangle.Y), New Point(Rectangle.X, ArcRectangleWidth + Rectangle.Y))
  81. RoundRect.CloseAllFigures()
  82. Return RoundRect
  83. End Function
  84.  
  85. Public Function RoundRect(ByVal X As Integer, ByVal Y As Integer, ByVal Width As Integer, ByVal Height As Integer, ByVal Curve As Integer) As GraphicsPath
  86. Return RoundRect(New Rectangle(X, Y, Width, Height), Curve)
  87. End Function
  88.  
  89. Class PillStyle
  90. Public Left As Boolean
  91. Public Right As Boolean
  92. End Class
  93.  
  94. Public Function Pill(ByVal Rectangle As Rectangle, ByVal PillStyle As PillStyle) As GraphicsPath
  95. Pill = New GraphicsPath()
  96.  
  97. If PillStyle.Left Then
  98. Pill.AddArc(New Rectangle(Rectangle.X, Rectangle.Y, Rectangle.Height, Rectangle.Height), -270, 180)
  99. Else
  100. Pill.AddLine(Rectangle.X, Rectangle.Y + Rectangle.Height, Rectangle.X, Rectangle.Y)
  101. End If
  102.  
  103. If PillStyle.Right Then
  104. Pill.AddArc(New Rectangle(Rectangle.X + Rectangle.Width - Rectangle.Height, Rectangle.Y, Rectangle.Height, Rectangle.Height), -90, 180)
  105. Else
  106. Pill.AddLine(Rectangle.X + Rectangle.Width, Rectangle.Y, Rectangle.X + Rectangle.Width, Rectangle.Y + Rectangle.Height)
  107. End If
  108.  
  109. Pill.CloseAllFigures()
  110.  
  111. Return Pill
  112. End Function
  113.  
  114. Public Function Pill(ByVal X As Integer, ByVal Y As Integer, ByVal Width As Integer, ByVal Height As Integer, ByVal PillStyle As PillStyle)
  115. Return Pill(New Rectangle(X, Y, Width, Height), PillStyle)
  116. End Function
  117.  
  118. End Module
  119. Class AresioTrackBar
  120. Inherits Panel
  121.  
  122. #Region "Properties"
  123. Dim _Maximum As Integer = 10
  124. Public Property inner As Boolean = False
  125. Public Property At As String = "00:00"
  126. Public Property Endd As String = "00:00"
  127. Public Property Maximum() As Integer
  128. Get
  129. Return _Maximum
  130. End Get
  131. Set(ByVal value As Integer)
  132. If value > 0 Then _Maximum = value
  133. If value < _Value Then _Value = value
  134. Invalidate()
  135. End Set
  136. End Property
  137. Event ClickedForward()
  138. Event ValueChanged()
  139. Public _Value As Integer = 0
  140. Public Property Value() As Integer
  141. Get
  142. Return _Value
  143. End Get
  144. Set(ByVal value As Integer)
  145.  
  146. Select Case value
  147. Case Is = _Value
  148. Exit Property
  149. Case Is < 0
  150. _Value = 0
  151. Case Is > _Maximum
  152. _Value = _Maximum
  153. Case Else
  154. _Value = value
  155. End Select
  156.  
  157. Invalidate()
  158. RaiseEvent ValueChanged()
  159. End Set
  160. End Property
  161. #End Region
  162.  
  163. Sub New()
  164. Me.SetStyle(ControlStyles.DoubleBuffer Or _
  165. ControlStyles.AllPaintingInWmPaint Or _
  166. ControlStyles.ResizeRedraw Or _
  167. ControlStyles.UserPaint Or _
  168. ControlStyles.Selectable Or _
  169. ControlStyles.SupportsTransparentBackColor, True)
  170. DoubleBuffered = True
  171. BackColor = Color.Transparent
  172. Parent = FindForm()
  173. End Sub
  174.  
  175. Dim CaptureM As Boolean = False
  176. Dim Bar As Rectangle = New Rectangle(0, 10, Width - 1, Height - 21)
  177. Dim Track As Size = New Size(20, 20)
  178.  
  179. Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
  180. MyBase.OnPaint(e)
  181. Dim G As Graphics = e.Graphics
  182. Bar = New Rectangle(10, 10, Width - 21, Height - 21)
  183. ' G.Clear(Parent.FindForm.BackColor)
  184. G.SmoothingMode = SmoothingMode.AntiAlias
  185.  
  186. 'Background
  187. Dim BackLinear As LinearGradientBrush = New LinearGradientBrush(New Rectangle(0, CInt((Height / 2) - 4 + 9), Width - 1, 8), Color.FromArgb(50, Color.Black), Color.Transparent, 90.0!)
  188. G.FillPath(BackLinear, RoundRect(0, CInt((Height / 2) - 4 + 9), Width - 1, 8, 3))
  189. G.DrawPath(ToPen(50, Color.Black), RoundRect(0, CInt((Height / 2) - 4 + 9), Width - 1, 8, 3))
  190. BackLinear.Dispose()
  191.  
  192.  
  193. 'Fill
  194. G.FillPath(New LinearGradientBrush(New Point(1, CInt((Height / 2) - 4)), New Point(1, CInt((Height / 2) + 9)), Color.FromArgb(251, 83, 150), Color.FromArgb(25, 25, 25)), RoundRect(1, CInt((Height / 2) - 4 + 9), CInt(Bar.Width * (Value / Maximum)) + CInt(Track.Width / 2), 8, 3))
  195. ' G.DrawPath(ToPen(100, Color.White), RoundRect(2, CInt((Height / 2) - 2), CInt(Bar.Width * (Value / Maximum)) + CInt(Track.Width / 2), 4, 3))
  196. G.SetClip(RoundRect(1, CInt((Height / 2) - 4 + 9), CInt(Bar.Width * (Value / Maximum)) + CInt(Track.Width / 2), 8, 3))
  197. For i = 0 To CInt(Bar.Width * (Value / Maximum)) + CInt(Track.Width / 2) Step 10
  198. G.DrawLine(New Pen(New SolidBrush(Color.FromArgb(20, Color.Black)), 4), New Point(i, CInt((Height / 2) - 10)), New Point(i - 10, CInt((Height / 2) + 10)))
  199. Next
  200. G.SetClip(New Rectangle(0, 0, Width, Height))
  201.  
  202. 'Button
  203.  
  204. 'G.FillEllipse(Brushes.White, Bar.X + CInt(Bar.Width * (Value / Maximum)) - CInt(Track.Width / 2), Bar.Y + CInt((Bar.Height / 2)) - CInt(Track.Height / 2), Track.Width, Track.Height)
  205. 'G.DrawEllipse(ToPen(50, Color.Black), Bar.X + CInt(Bar.Width * (Value / Maximum)) - CInt(Track.Width / 2), Bar.Y + CInt((Bar.Height / 2)) - CInt(Track.Height / 2), Track.Width, Track.Height)
  206. 'G.FillEllipse(New LinearGradientBrush(New Point(0, Bar.Y + CInt((Bar.Height / 2)) - CInt(Track.Height / 2)), New Point(0, Bar.Y + CInt((Bar.Height / 2)) - CInt(Track.Height / 2) + Track.Height), Color.FromArgb(200, Color.Black), Color.FromArgb(100, Color.Black)), New Rectangle(Bar.X + CInt(Bar.Width * (Value / Maximum)) - CInt(Track.Width / 2) + 6, Bar.Y + CInt((Bar.Height / 2)) - CInt(Track.Height / 2) + 6, Track.Width - 12, Track.Height - 12))
  207. If inner = True Then
  208. G.FillEllipse(Brushes.White, Bar.X + CInt(Bar.Width * (Value / Maximum)) - CInt(Track.Width / 2), Bar.Y + CInt((Bar.Height / 2)) - CInt(Track.Height / 2) + 9, Track.Width, Track.Height)
  209. G.DrawEllipse(ToPen(50, Color.Black), Bar.X + CInt(Bar.Width * (Value / Maximum)) - CInt(Track.Width / 2), Bar.Y + CInt((Bar.Height / 2)) - CInt(Track.Height / 2) + 9, Track.Width, Track.Height)
  210. G.FillEllipse(New LinearGradientBrush(New Point(0, Bar.Y + CInt((Bar.Height / 2)) - CInt(Track.Height / 2)), New Point(0, Bar.Y + CInt((Bar.Height / 2)) - CInt(Track.Height / 2) + Track.Height), Color.FromArgb(200, Color.Black), Color.FromArgb(100, Color.Black)), New Rectangle(Bar.X + CInt(Bar.Width * (Value / Maximum)) - CInt(Track.Width / 2) + 6, Bar.Y + CInt((Bar.Height / 2)) - CInt(Track.Height / 2) + 15, Track.Width - 12, Track.Height - 12))
  211. Dim poiints As PointF() = {New Point(Bar.X + CInt(Bar.Width * (Value / Maximum)) - CInt(Track.Width / 2), Bar.Y + CInt((Bar.Height / 2)) - CInt(Track.Height / 2) + 9), New Point(Bar.X + CInt(Bar.Width * (Value / Maximum)) - CInt(Track.Width / 2) + 10, Bar.Y + CInt((Bar.Height / 2)) - CInt(Track.Height / 2) + 19), New Point(Bar.X + CInt(Bar.Width * (Value / Maximum)) - CInt(Track.Width / 2) + 20, Bar.Y + CInt((Bar.Height / 2)) - CInt(Track.Height / 2) + 9)}
  212. G.FillPolygon(Brushes.White, poiints)
  213. e.Graphics.FillRectangle(New SolidBrush(Color.White), New Rectangle(New Point(Bar.X + CInt(Bar.Width * (Value / Maximum)) - CInt(Track.Width / 2) - 22, 0), New Size(65, 16)))
  214. e.Graphics.DrawRectangle(New Pen(Color.DimGray), New Rectangle(New Point(Bar.X + CInt(Bar.Width * (Value / Maximum)) - CInt(Track.Width / 2) - 22, 0), New Size(65, 17)))
  215. e.Graphics.DrawString(At & "|" & Endd, New Font("Arial", 8, FontStyle.Regular), New SolidBrush(Color.FromArgb(25, 25, 25)), New Rectangle(New Point(Bar.X + CInt(Bar.Width * (Value / Maximum)) - CInt(Track.Width / 2) - 22, 0), New Size(65, 16)), New StringFormat With {.Alignment = StringAlignment.Center, .LineAlignment = StringAlignment.Center})
  216. Else
  217. G.FillEllipse(Brushes.White, Bar.X + CInt(Bar.Width * (Value / Maximum)) - CInt(Track.Width / 2), Bar.Y + CInt((Bar.Height / 2)) - CInt(Track.Height / 2) + 9, Track.Width, Track.Height)
  218. G.DrawEllipse(ToPen(50, Color.Black), Bar.X + CInt(Bar.Width * (Value / Maximum)) - CInt(Track.Width / 2), Bar.Y + CInt((Bar.Height / 2)) - CInt(Track.Height / 2) + 9, Track.Width, Track.Height)
  219. G.FillEllipse(New LinearGradientBrush(New Point(0, Bar.Y + CInt((Bar.Height / 2)) - CInt(Track.Height / 2)), New Point(0, Bar.Y + CInt((Bar.Height / 2)) - CInt(Track.Height / 2) + Track.Height), Color.FromArgb(200, Color.Black), Color.FromArgb(100, Color.Black)), New Rectangle(Bar.X + CInt(Bar.Width * (Value / Maximum)) - CInt(Track.Width / 2) + 6, Bar.Y + CInt((Bar.Height / 2)) - CInt(Track.Height / 2) + 15, Track.Width - 12, Track.Height - 12))
  220. End If
  221. End Sub
  222.  
  223. Protected Overrides Sub OnHandleCreated(ByVal e As System.EventArgs)
  224. Me.BackColor = Color.Transparent
  225.  
  226. MyBase.OnHandleCreated(e)
  227. End Sub
  228.  
  229. Protected Overrides Sub OnMouseDown(ByVal e As System.Windows.Forms.MouseEventArgs)
  230. MyBase.OnMouseDown(e)
  231. Dim mp = New Rectangle(New Point(e.Location.X, e.Location.Y), New Size(20, 20))
  232. Dim Bar As Rectangle = New Rectangle(10, 10, Width - 21, Height - 21)
  233. If New Rectangle(New Point(Bar.X + CInt(Bar.Width * (Value / Maximum)) - CInt(Track.Width / 2), 19), New Size(Track.Width, Height)).Contains(e.Location) Then
  234. CaptureM = True
  235. inner = Not inner
  236. End If
  237. If e.Button = Windows.Forms.MouseButtons.Left Then
  238.  
  239. Dim mousepos = Math.Min(Math.Max(e.X, 0), Me.ClientSize.Width)
  240. Dim value = CInt(0 + (Me.Maximum - 0) * mousepos / Me.ClientSize.Width)
  241. '' Disable animation, if possible
  242. If value > Me.Value And value < Me.Maximum Then
  243. Me.Value = value + 1
  244. Me.Value = value
  245. Else
  246. Me.Value = value
  247. End If
  248.  
  249. End If
  250. RaiseEvent ClickedForward()
  251. End Sub
  252.  
  253. Protected Overrides Sub OnMouseUp(ByVal e As System.Windows.Forms.MouseEventArgs)
  254. MyBase.OnMouseUp(e)
  255. CaptureM = False
  256. End Sub
  257.  
  258. Protected Overrides Sub OnMouseMove(ByVal e As System.Windows.Forms.MouseEventArgs)
  259. MyBase.OnMouseMove(e)
  260. If CaptureM Then
  261. Dim mp As Point = New Point(e.X, e.Y)
  262. Dim Bar As Rectangle = New Rectangle(10, 10, Width - 21, Height - 21)
  263. Value = CInt(Maximum * ((mp.X - Bar.X) / Bar.Width))
  264. RaiseEvent ClickedForward()
  265. End If
  266. 'Dim mp2 = New Rectangle(New Point(e.Location.X, e.Location.Y), New Size(1, 1))
  267. 'Dim Bar2 As Rectangle = New Rectangle(10, 10, Width - 21, Height - 21)
  268. 'If New Rectangle(New Point(Bar.X + CInt(Bar.Width * (Value / Maximum)) - CInt(Track.Width / 2), Bar.Y + CInt((Bar.Height / 2)) - CInt(Track.Height / 2) + 9), New Size(Track.Width, Height)).Contains(e.Location) Then
  269. ' inner = True
  270. 'Else
  271. ' inner = False
  272. 'End If
  273. End Sub
  274.  
  275. Protected Overrides Sub OnMouseLeave(ByVal e As System.EventArgs)
  276. MyBase.OnMouseLeave(e) : CaptureM = False
  277. End Sub
  278.  
  279. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement