Advertisement
netrosly

Circle Group

Dec 23rd, 2014
440
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.78 KB | None | 0 0
  1. 'This may be messy so if you are trying to learn from it, ... i would say don't xD!
  2. Public Class CicleGroup
  3. Inherits Panel
  4.  
  5. Dim inner As Boolean = False
  6. Public List As New List(Of Item)
  7. Property refreshh As Boolean = True
  8. Dim TRC1 As Integer = 20
  9. Public Sub New()
  10. BackColor = Color.Transparent
  11. SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.UserPaint Or _
  12. ControlStyles.ResizeRedraw Or ControlStyles.OptimizedDoubleBuffer Or _
  13. ControlStyles.SupportsTransparentBackColor, True)
  14. DoubleBuffered = True
  15. BackColor = Color.Transparent
  16. Parent = FindForm()
  17.  
  18. End Sub
  19. Public Class ItemCollection
  20. Inherits List(Of Item)
  21. Private Parent As CicleGroup
  22. Public Sub New(Parent As CicleGroup)
  23. Me.Parent = Parent
  24. End Sub
  25. Public Shadows Sub Add(Item As Item)
  26.  
  27. MyBase.Add(Item)
  28. End Sub
  29. Public Shadows Sub AddRange(Range As List(Of Item))
  30. MyBase.AddRange(Range)
  31. End Sub
  32. Public Shadows Sub Clear()
  33. MyBase.Clear()
  34. End Sub
  35. Public Shadows Sub Remove(Item As Item)
  36. MyBase.Remove(Item)
  37. End Sub
  38. Public Shadows Sub RemoveAt(Index As Integer)
  39. MyBase.RemoveAt(Index)
  40. End Sub
  41. Public Shadows Sub RemoveAll(Predicate As System.Predicate(Of Item))
  42. MyBase.RemoveAll(Predicate)
  43. End Sub
  44. Public Shadows Sub RemoveRange(Index As Integer, Count As Integer)
  45. MyBase.RemoveRange(Index, Count)
  46. End Sub
  47.  
  48. End Class
  49. Public Class Item
  50. Property Text As String
  51. Property Fill_Color As Color = Color.FromArgb(100, 45, 45, 45)
  52. Property Index As Integer = 0
  53. Property Icon As Image = My.Resources.LightStar
  54. Property Iconn As Boolean = False
  55. Property locx As Integer = 0
  56. Property locy As Integer = 0
  57. Protected UniqueId As Guid
  58. Sub New()
  59. UniqueId = Guid.NewGuid()
  60. End Sub
  61. Public Overrides Function ToString() As String
  62. Return Text
  63. End Function
  64.  
  65. Public Overrides Function Equals(obj As Object) As Boolean
  66. If TypeOf obj Is Item Then
  67. Return (DirectCast(obj, Item).UniqueId = UniqueId)
  68. End If
  69. Return False
  70. End Function
  71.  
  72. End Class
  73. Public _Items As New ItemCollection(Me)
  74. <DesignerSerializationVisibility(DesignerSerializationVisibility.Content)> _
  75. Public Property Items As ItemCollection
  76. Get
  77. Return _Items
  78. End Get
  79. Set(ByVal value As ItemCollection)
  80. _Items = value
  81. End Set
  82. End Property
  83. Public List2 As New List(Of Point)
  84. Private Sub CicleGroup_Paint(sender As Object, e As PaintEventArgs) Handles Me.Paint
  85. If refreshh = True Then
  86. Try
  87. _Items.Clear()
  88. Catch ex As Exception
  89.  
  90. End Try
  91. refreshh = False
  92. End If
  93. Dim i2 As Integer = 0
  94. For Each itm As Item In _Items
  95. i2 += 1
  96. Next
  97.  
  98. e.Graphics.SmoothingMode = Drawing2D.SmoothingMode.HighQuality
  99.  
  100.  
  101. Dim rnd As New Random
  102. If i2 = 0 Then
  103. For i As Integer = 0 To 50
  104. Dim item As New Item
  105. item.locx = rnd.Next(0, Me.Width - 23)
  106. item.locy = rnd.Next(0, Me.Height - 23)
  107. _Items.Add(Item)
  108. Next
  109. End If
  110. For Each itm As Item In _Items
  111. e.Graphics.DrawLine(Pens.Black, New Point(Me.Width / 2, Me.Height / 2), New Point(itm.locx, itm.locy))
  112. If Not New Rectangle(itm.locx, itm.locy, 25, 25).Contains(New Rectangle(Me.Width / 2 - 25, Me.Height / 2 - 25, 50, 50)) Then
  113. Dim r As Integer = rnd.Next(0, 205)
  114. Dim g As Integer = rnd.Next(0, 205)
  115. Dim b As Integer = rnd.Next(0, 205)
  116. 'Dim pic As New PictureBox
  117. 'pic.Location = New Point(itm.locx - 1, itm.locy - 1)
  118. 'pic.Size = New Size(16, 16)
  119. 'pic.Image = itm.Icon
  120. 'pic.Name = "pic_" & itm.Text
  121. 'pic.SizeMode = PictureBoxSizeMode.Zoom
  122. e.Graphics.FillEllipse(New SolidBrush(Color.FromArgb(r, g, b)), New Rectangle(itm.locx - 6, itm.locy - 6, 26, 26))
  123. e.Graphics.DrawImage(itm.Icon, New Rectangle(itm.locx - 3, itm.locy - 3, 20, 20))
  124. 'Me.Controls.Add(pic)
  125.  
  126. 'pic.Region = New Region(RoundedRec(0, 0, pic.Width - TRC1 * 4, pic.Height - TRC1 * 4))
  127. End If
  128. Next
  129.  
  130. e.Graphics.FillEllipse(New SolidBrush(Color.FromArgb(68, 148, 248)), New Rectangle(Me.Width / 2 - 25, Me.Height / 2 - 25, 50, 50))
  131. refreshh = False
  132.  
  133. For Each itm As Item In _Items
  134. If New Rectangle(itm.locx, itm.locy, 25, 25).Contains(mouseX, mouseY) Then
  135. Cursor = Cursors.Hand
  136. e.Graphics.DrawString(itm.Text, Font, Brushes.Brown, New Rectangle(mouseX + 38, mouseY, 50, 50))
  137. e.Graphics.FillEllipse(New SolidBrush(Color.FromArgb(68, 148, 248)), New Rectangle(itm.locx - 26, itm.locy - 26, 66, 66))
  138. 'Dim pic As New PictureBox
  139. 'pic.Location = New Point(itm.locx - 23, itm.locy - 23)
  140. 'pic.Size = New Size(60, 60)
  141. 'pic.Image = itm.Icon
  142. 'pic.SizeMode = PictureBoxSizeMode.Zoom
  143. 'pic.Name = "Hover_pic" & rnd.Next(1, 999)
  144. 'Me.Controls.Add(pic)
  145. 'For Each pic2 As PictureBox In Me.Controls.OfType(Of PictureBox)()
  146. ' If pic2.Name.Contains(itm.Text) Then
  147. ' pic2.Visible = False
  148. ' End If
  149. 'Next
  150. e.Graphics.DrawImage(itm.Icon, New Rectangle(itm.locx - 23, itm.locy - 23, 60, 60))
  151. Else
  152. 'For Each pic As PictureBox In Me.Controls.OfType(Of PictureBox)()
  153. ' If pic.Name.Contains("Hover_pic") Then
  154. ' pic.Dispose()
  155. ' End If
  156. 'Next
  157. Cursor = Cursors.Arrow
  158. End If
  159. Next
  160. End Sub
  161. #Region "ThemeDraggable"
  162.  
  163. Private savePoint As New Point(0, 0)
  164. Private isDragging As Boolean = False
  165. Dim x, y As Integer
  166. Protected Overrides Sub OnMouseDown(e As MouseEventArgs)
  167.  
  168.  
  169. '
  170. MyBase.OnMouseDown(e)
  171. End Sub
  172.  
  173. Protected Overrides Sub OnMouseUp(e As MouseEventArgs)
  174. isDragging = False
  175. MyBase.OnMouseUp(e)
  176. End Sub
  177.  
  178. Private mouseX As Integer
  179. Private mouseY As Integer
  180. Protected Overrides Sub OnMouseMove(e As MouseEventArgs)
  181.  
  182. mouseX = e.X
  183. mouseY = e.Y
  184.  
  185. If isDragging Then
  186. Dim screenPoint As Point = PointToScreen(e.Location)
  187.  
  188. FindForm().Location = New Point(screenPoint.X - Me.savePoint.X, screenPoint.Y - Me.savePoint.Y)
  189. End If
  190. For Each itm In List
  191. If New Rectangle(itm.locx, itm.locy, 25, 25).Contains(mouseX, mouseY) Then
  192. inner = True
  193.  
  194. Else
  195. inner = False
  196. End If
  197. Next
  198.  
  199. MyBase.OnMouseMove(e)
  200. Invalidate()
  201. End Sub
  202.  
  203. #End Region
  204.  
  205. Private Sub pic_load()
  206.  
  207. End Sub
  208. Private Function RoundedRec(ByVal X As Integer, ByVal Y As Integer, ByVal Width As Integer, ByVal Height As Integer) As System.Drawing.Drawing2D.GraphicsPath
  209. ' Make and Draw a path.
  210. Dim graphics_path As New System.Drawing.Drawing2D.GraphicsPath
  211. graphics_path.AddLine(X + 10, Y, X + Width, Y) 'add the Top line to the path
  212. Dim TRC1 As Integer = 20 * 4
  213. Dim TRC2 As Integer = 4 * 4
  214. Dim TRC3 As Integer = 12 * 4
  215. Dim TRC4 As Integer = 8 * 4
  216. Dim TRC5 As Integer = 16 * 4
  217. 'Top Right corner
  218. Dim tr() As Point = { _
  219. New Point(X + Width, Y), _
  220. New Point((X + Width) + TRC4, Y + TRC2), _
  221. New Point((X + Width) + TRC5, Y + TRC3), _
  222. New Point((X + Width) + TRC1, Y + TRC1)}
  223.  
  224. graphics_path.AddCurve(tr) 'Add the Top right curve to the path
  225.  
  226. 'Bottom right corner
  227. Dim BRC1 As Integer = 20 * 4
  228. Dim BRC2 As Integer = 4 * 4
  229. Dim BRC3 As Integer = 12 * 4
  230. Dim BRC4 As Integer = 8 * 4
  231. Dim BRC5 As Integer = 16 * 4
  232. Dim br() As Point = { _
  233. New Point((X + Width) + BRC1, Y + Height), _
  234. New Point((X + Width) + BRC5, (Y + Height) + BRC4), _
  235. New Point((X + Width) + BRC4, (Y + Height) + BRC5), _
  236. New Point(X + Width, (Y + Height) + BRC1)}
  237.  
  238. graphics_path.AddCurve(br) 'Add the Bottom right curve to the path
  239.  
  240. 'Bottom left corner
  241. Dim BLC1 As Integer = 20 * 4
  242. Dim BLC2 As Integer = 4 * 4
  243. Dim BLC3 As Integer = 12 * 4
  244. Dim BLC4 As Integer = 8 * 4
  245. Dim BLC5 As Integer = 16 * 4
  246. Dim bl() As Point = { _
  247. New Point(X + BLC1, (Y + Height) + BLC1), _
  248. New Point(X + BLC3, (Y + Height) + BLC5), _
  249. New Point(X + BLC2, (Y + Height) + BLC4), _
  250. New Point(X, Y + Height)}
  251.  
  252. graphics_path.AddCurve(bl) 'Add the Bottom left curve to the path
  253. Dim TLC1 As Integer = 20 * 4
  254. Dim TLC2 As Integer = 4 * 4
  255. Dim TLC3 As Integer = 12 * 4
  256. 'Top left corner
  257. Dim tl() As Point = { _
  258. New Point(X, Y + TLC1), _
  259. New Point(X + TLC2, Y + TLC3), _
  260. New Point(X + TLC3, Y + TLC2), _
  261. New Point(X + TLC1, Y)}
  262.  
  263. graphics_path.AddCurve(tl) 'add the Top left curve to the path
  264.  
  265. Return graphics_path
  266.  
  267. End Function
  268. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement