netrosly

PureFlat Theme - VB.NET

Dec 24th, 2014
477
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 46.86 KB | None | 0 0
  1. Imports System.Drawing.Drawing2D
  2. Imports System.IO
  3. Imports System.ComponentModel
  4.  
  5. <DefaultEvent("CheckedChanged")> Class Toggle : Inherits Panel
  6. Property FillColor As Color = Color.FromArgb(27, 132, 188)
  7. Public onoff As Boolean = False
  8. Public Event CheckedChanged(ByVal sender As Object)
  9. Public Sub New()
  10. Me.SetStyle(ControlStyles.DoubleBuffer Or ControlStyles.AllPaintingInWmPaint Or ControlStyles.UserPaint, True)
  11. DoubleBuffered = True
  12. Me.Size = New Size(44, 18)
  13. End Sub
  14.  
  15. <PropertyTab("Onoff")> _
  16. <DisplayName("Onoff")> _
  17. Public Property Icons() As Boolean
  18. Get
  19. Return onoff
  20. End Get
  21. Set(value As Boolean)
  22. onoff = value
  23. End Set
  24. End Property
  25. Friend NearSF As New StringFormat() With {.Alignment = StringAlignment.Near, .LineAlignment = StringAlignment.Near}
  26. Protected Overrides Sub OnPaint(e As PaintEventArgs)
  27. Dim bm As New Bitmap(Me.Width, Me.Height)
  28. Dim g As Graphics = Graphics.FromImage(bm)
  29. ' Me.Padding = New Padding(13, 39, 13, 24)
  30. ' Dim rect As New Rectangle(0, 0, Me.Width, (Me.Height - 35))
  31. ' Dim brush As New LinearGradientBrush(rect, Color.FromArgb(250, 250, 250), Color.FromArgb(206, 206, 206), 90.0!)
  32. 'Begin
  33. If onoff = True Then
  34. Dim Path As GraphicsPath = RoundRec(0, 0, Width - 2, Height - 2, 14)
  35. g.SmoothingMode = SmoothingMode.HighQuality
  36. g.FillPath(New SolidBrush(FillColor), Path)
  37. g.DrawPath(New Pen(FillColor), Path) '22, 122, 198
  38. g.DrawEllipse(New Pen(Color.FromArgb(255, 255, 255)), New Rectangle(Width - 17, Me.Height - 17, 14, 14))
  39. g.FillEllipse(New SolidBrush(Color.FromArgb(255, 255, 255)), New Rectangle(Width - 17, Me.Height - 17, 14, 14))
  40. g.DrawString("ΓΌ", New Font("Wingdings", 14), New SolidBrush(Color.FromArgb(255, 255, 255)), New Rectangle(0 + 7, Me.Height - 19, 14, 14), NearSF)
  41. Else
  42. Dim Path As GraphicsPath = RoundRec(0, 0, Width - 2, Height - 2, 14)
  43. g.SmoothingMode = SmoothingMode.HighQuality
  44. g.FillPath(New SolidBrush(Color.FromArgb(184, 184, 184)), Path)
  45. g.DrawPath(New Pen(Color.FromArgb(184, 184, 184)), Path)
  46. g.DrawEllipse(New Pen(Color.FromArgb(255, 255, 255)), New Rectangle(0 + 1, Me.Height - 17, 14, 14))
  47. g.FillEllipse(New SolidBrush(Color.FromArgb(255, 255, 255)), New Rectangle(0 + 1, Me.Height - 17, 14, 14))
  48. End If
  49. 'end
  50. e.Graphics.DrawImage(DirectCast(bm.Clone(), Bitmap), 0, 0)
  51. g.Dispose()
  52. bm.Dispose()
  53. MyBase.OnPaint(e)
  54. End Sub
  55. Dim x, y As Integer
  56. Private _Checked As Boolean = False
  57. #Region " Options"
  58.  
  59. <Category("Options")> _
  60. Public Property Checked As Boolean
  61. Get
  62. Return _Checked
  63. End Get
  64. Set(value As Boolean)
  65. _Checked = value
  66. End Set
  67. End Property
  68.  
  69. #End Region
  70. #Region "ThemeDraggable"
  71.  
  72. Private savePoint As New Point(0, 0)
  73. Private isDragging As Boolean = False
  74.  
  75. Protected Overrides Sub OnMouseDown(e As MouseEventArgs)
  76.  
  77. Dim clickRect2 As New Rectangle(0 + 1, Me.Height - 17, 14, 14)
  78. If onoff = False Then
  79. If clickRect2.Contains(New Point(e.X, e.Y)) Then
  80. onoff = True
  81. RaiseEvent CheckedChanged(Me)
  82. End If
  83. End If
  84. Dim clickRect3 As New Rectangle(Width - 17, Me.Height - 17, 14, 14)
  85. If onoff = True Then
  86. If clickRect3.Contains(New Point(e.X, e.Y)) Then
  87. onoff = False
  88. RaiseEvent CheckedChanged(Me)
  89. End If
  90. End If
  91. MyBase.OnMouseDown(e)
  92. End Sub
  93.  
  94. Protected Overrides Sub OnMouseUp(e As MouseEventArgs)
  95. isDragging = False
  96. MyBase.OnMouseUp(e)
  97. End Sub
  98.  
  99. Private mouseX As Integer
  100. Private mouseY As Integer
  101. Protected Overrides Sub OnMouseMove(e As MouseEventArgs)
  102. mouseX = e.X
  103. mouseY = e.Y
  104. MyBase.OnMouseMove(e)
  105. Invalidate()
  106. End Sub
  107. #End Region
  108. Private Sub Theme_Resize(sender As Object, e As EventArgs) Handles Me.Resize
  109. Me.Refresh()
  110. End Sub
  111. Public Function RoundRec(ByVal X As Integer, ByVal Y As Integer, _
  112. ByVal Width As Integer, ByVal Height As Integer, ByVal diameter As Integer) As System.Drawing.Drawing2D.GraphicsPath
  113.  
  114. ''the 'diameter' parameter changes the size of the rounded region
  115.  
  116. Dim graphics_path As New System.Drawing.Drawing2D.GraphicsPath
  117.  
  118. Dim BaseRect As New RectangleF(X, Y, Width, Height)
  119. Dim ArcRect As New RectangleF(BaseRect.Location, New SizeF(diameter, diameter))
  120.  
  121. 'top left Arc
  122. graphics_path.AddArc(ArcRect, 180, 90)
  123. graphics_path.AddLine(X + CInt(diameter / 2), _
  124. Y, X + Width - CInt(diameter / 2), Y)
  125.  
  126. ' top right arc
  127. ArcRect.X = BaseRect.Right - diameter
  128. graphics_path.AddArc(ArcRect, 270, 90)
  129. graphics_path.AddLine(X + Width, _
  130. Y + CInt(diameter / 2), X + Width, _
  131. Y + Height - CInt(diameter / 2))
  132.  
  133. ' bottom right arc
  134. ArcRect.Y = BaseRect.Bottom - diameter
  135. graphics_path.AddArc(ArcRect, 0, 90)
  136. graphics_path.AddLine(X + CInt(diameter / 2), _
  137. Y + Height, X + Width - CInt(diameter / 2), _
  138. Y + Height)
  139.  
  140. ' bottom left arc
  141. ArcRect.X = BaseRect.Left
  142. graphics_path.AddArc(ArcRect, 90, 90)
  143. graphics_path.AddLine(X, Y + CInt(diameter / 2), _
  144. X, Y + Height - CInt(diameter / 2))
  145.  
  146. Return graphics_path
  147.  
  148. End Function
  149.  
  150. End Class
  151.  
  152. Partial Public Class ContainerTheme
  153. Inherits Panel
  154. Public Sub New()
  155. Me.SetStyle(ControlStyles.DoubleBuffer Or ControlStyles.AllPaintingInWmPaint Or ControlStyles.UserPaint, True)
  156. DoubleBuffered = True
  157. Me.Padding = New Padding(1, 55, 1, 1)
  158. End Sub
  159. Dim x, y As Integer
  160. Public Enum Type
  161. Teacher = 0
  162. Student = 1
  163. Application = 2
  164. End Enum
  165. Public _Type As Type = Type.Student
  166. Public Property Tyype As Type
  167. Get
  168. Return _Type
  169. End Get
  170. Set(ByVal value As Type)
  171. _Type = value
  172. Invalidate()
  173. End Set
  174. End Property
  175. Protected Overrides Sub OnPaint(e As PaintEventArgs)
  176. Dim bm As New Bitmap(Me.Width, Me.Height)
  177. Dim g As Graphics = Graphics.FromImage(bm)
  178. ' Dim rect As New Rectangle(0, 0, Me.Width, (Me.Height - 35))
  179. ' Dim brush As New LinearGradientBrush(rect, Color.FromArgb(250, 250, 250), Color.FromArgb(206, 206, 206), 90.0!)
  180. 'Begin
  181. 'Form
  182. g.DrawRectangle(New Pen(Color.FromArgb(242, 242, 242)), 0, 0, Me.Width, Me.Height)
  183. g.FillRectangle(New SolidBrush(Color.FromArgb(242, 242, 242)), 0, 0, Me.Width, Me.Height)
  184. 'Splitter
  185. g.DrawRectangle(New Pen(Color.FromArgb(229, 229, 229)), 0, 0, Me.Width, 51)
  186. g.FillRectangle(New SolidBrush(Color.FromArgb(229, 229, 229)), 0, 0, Me.Width, 51)
  187. 'Top
  188. Dim rect = New Rectangle(0, 0, Me.Width, 50)
  189. g.DrawRectangle(New Pen(Color.FromArgb(255, 255, 255)), 0, 0, Me.Width, 50)
  190. g.FillRectangle(New SolidBrush(Color.FromArgb(255, 255, 255)), 0, 0, Me.Width, 50)
  191. 'String
  192. g.DrawString(FindForm.Text, New Font("Arial", 12.5, FontStyle.Regular), New SolidBrush(Color.FromArgb(130, 130, 130)), 14, 17)
  193. g.DrawString(_Type.ToString, New Font("Arial", 12.5, FontStyle.Bold), New SolidBrush(Color.FromArgb(45, 114, 160)), 93, 17)
  194. 'Buttons
  195. '//Close button
  196. If New Rectangle(Width - 40, 10, 24, 24).Contains(New Point(mouseX, mouseY)) Then
  197. g.SmoothingMode = SmoothingMode.HighQuality
  198. g.FillRectangle(New SolidBrush(Color.FromArgb(237, 237, 237)), New Rectangle(Width - 40, 10, 24, 24))
  199. g.DrawString("r", New Font("Webdings", 14), New SolidBrush(Color.FromArgb(130, 130, 130)), New Point(Width - 40, 10))
  200. Else
  201. g.SmoothingMode = SmoothingMode.HighQuality
  202. ' g.FillRectangle(New SolidBrush(Color.FromArgb(237, 237, 237)), New Rectangle(Width - 40, 10, 24, 24))
  203. g.DrawString("r", New Font("Webdings", 14), New SolidBrush(Color.FromArgb(130, 130, 130)), New Point(Width - 40, 10))
  204. End If
  205. '//Minimize Button
  206. If New Rectangle(Width - 100, 10, 24, 24).Contains(New Point(mouseX, mouseY)) Then
  207. g.SmoothingMode = SmoothingMode.HighQuality
  208. g.FillRectangle(New SolidBrush(Color.FromArgb(237, 237, 237)), New Rectangle(Width - 100, 10, 24, 24))
  209. g.DrawString("0", New Font("Webdings", 14), New SolidBrush(Color.FromArgb(130, 130, 130)), New Point(Width - 100, 10))
  210. Else
  211. g.SmoothingMode = SmoothingMode.HighQuality
  212. ' g.FillRectangle(New SolidBrush(Color.FromArgb(237, 237, 237)), New Rectangle(Width - 40, 10, 24, 24))
  213. g.DrawString("0", New Font("Webdings", 14), New SolidBrush(Color.FromArgb(130, 130, 130)), New Point(Width - 100, 10))
  214. End If
  215. '//Fullscreen
  216. If New Rectangle(Width - 70, 10, 24, 24).Contains(New Point(mouseX, mouseY)) Then
  217. g.SmoothingMode = SmoothingMode.HighQuality
  218. g.FillRectangle(New SolidBrush(Color.FromArgb(237, 237, 237)), New Rectangle(Width - 70, 10, 24, 24))
  219. If FindForm.WindowState = FormWindowState.Maximized Then
  220. g.DrawString("2", New Font("Webdings", 14), New SolidBrush(Color.FromArgb(130, 130, 130)), New Point(Width - 70, 10))
  221. Else
  222. g.DrawString("1", New Font("Webdings", 14), New SolidBrush(Color.FromArgb(130, 130, 130)), New Point(Width - 70, 10))
  223. End If
  224. Else
  225. g.SmoothingMode = SmoothingMode.HighQuality
  226. ' g.FillRectangle(New SolidBrush(Color.FromArgb(237, 237, 237)), New Rectangle(Width - 40, 10, 24, 24))
  227. If FindForm.WindowState = FormWindowState.Maximized Then
  228. g.DrawString("2", New Font("Webdings", 14), New SolidBrush(Color.FromArgb(130, 130, 130)), New Point(Width - 70, 10))
  229. Else
  230. g.DrawString("1", New Font("Webdings", 14), New SolidBrush(Color.FromArgb(130, 130, 130)), New Point(Width - 70, 10))
  231. End If
  232. End If
  233. 'End
  234. e.Graphics.DrawImage(DirectCast(bm.Clone(), Bitmap), 0, 0)
  235. g.Dispose()
  236. bm.Dispose()
  237. MyBase.OnPaint(e)
  238.  
  239. End Sub
  240. #Region "ThemeDraggable"
  241.  
  242. Private savePoint As New Point(0, 0)
  243. Private isDragging As Boolean = False
  244.  
  245. Protected Overrides Sub OnMouseDown(e As MouseEventArgs)
  246. Dim dragRect As New Rectangle(0, 0, Me.Width - 103, 50)
  247. If dragRect.Contains(New Point(e.X, e.Y)) Then
  248. isDragging = True
  249. savePoint = New Point(e.X, e.Y)
  250. End If
  251. Dim clickRect As New Rectangle(Width - 40, 10, 24, 24)
  252. If clickRect.Contains(New Point(e.X, e.Y)) Then
  253. Environment.[Exit](0)
  254. End If
  255. If New Rectangle(Width - 70, 10, 24, 24).Contains(New Point(mouseX, mouseY)) Then
  256. If FindForm.WindowState = FormWindowState.Maximized Then
  257. FindForm.WindowState = FormWindowState.Normal
  258. Else
  259. FindForm.WindowState = FormWindowState.Maximized
  260. End If
  261. End If
  262. If New Rectangle(Width - 100, 10, 24, 24).Contains(New Point(mouseX, mouseY)) Then
  263. FindForm.WindowState = FormWindowState.Minimized
  264. End If
  265. '
  266. MyBase.OnMouseDown(e)
  267. End Sub
  268.  
  269. Protected Overrides Sub OnMouseUp(e As MouseEventArgs)
  270. isDragging = False
  271. MyBase.OnMouseUp(e)
  272. End Sub
  273.  
  274. Private mouseX As Integer
  275. Private mouseY As Integer
  276. Protected Overrides Sub OnMouseMove(e As MouseEventArgs)
  277.  
  278. mouseX = e.X
  279. mouseY = e.Y
  280. If isDragging Then
  281. Dim screenPoint As Point = PointToScreen(e.Location)
  282.  
  283. FindForm().Location = New Point(screenPoint.X - Me.savePoint.X, screenPoint.Y - Me.savePoint.Y)
  284. End If
  285. MyBase.OnMouseMove(e)
  286. Invalidate()
  287. End Sub
  288.  
  289. #End Region
  290. Public Function Base64ToImage(base64String As String) As Image
  291. 'I did not write this Function
  292. ' Convert Base64 String to byte[]
  293. Dim imageBytes As Byte() = Convert.FromBase64String(base64String)
  294. Dim ms As New MemoryStream(imageBytes, 0, imageBytes.Length)
  295.  
  296. ' Convert byte[] to Image
  297. ms.Write(imageBytes, 0, imageBytes.Length)
  298. Dim image__1 As Image = Image.FromStream(ms, True)
  299. Return image__1
  300. End Function
  301. End Class
  302. Partial Public Class FlatButton
  303. Inherits Panel
  304. Public Sub New()
  305. Me.SetStyle(ControlStyles.DoubleBuffer Or ControlStyles.AllPaintingInWmPaint Or ControlStyles.UserPaint, True)
  306. DoubleBuffered = True
  307. End Sub
  308. Public Event Clicked()
  309. Public MainColor As Color = Color.FromArgb(33, 159, 225)
  310. Public PopColor As Color = Color.FromArgb(16, 110, 159)
  311. Public HoverColor As Color = Color.FromArgb(27, 132, 188)
  312. Public TextColor As Color = Color.FromArgb(255, 255, 255)
  313. Public TextFont As Font = New Font("Arial", 11, FontStyle.Regular)
  314. <PropertyTab("Main Color")> _
  315. <DisplayName("Main Color")> _
  316. Public Property MC() As Color
  317. Get
  318. Return MainColor
  319. End Get
  320. Set(value As Color)
  321. MainColor = value
  322. End Set
  323. End Property
  324. <PropertyTab("Pop Color")> _
  325. <DisplayName("Pop Color")> _
  326. Public Property PC() As Color
  327. Get
  328. Return PopColor
  329. End Get
  330. Set(value As Color)
  331. PopColor = value
  332. End Set
  333. End Property
  334. <PropertyTab("Hover Color")> _
  335. <DisplayName("Hover Color")> _
  336. Public Property HC() As Color
  337. Get
  338. Return HoverColor
  339. End Get
  340. Set(value As Color)
  341. HoverColor = value
  342. End Set
  343. End Property
  344. <PropertyTab("Text Color")> _
  345. <DisplayName("Text Color")> _
  346. Public Property TC() As Color
  347. Get
  348. Return TextColor
  349. End Get
  350. Set(value As Color)
  351. TextColor = value
  352. End Set
  353. End Property
  354. <PropertyTab("Text Font")> _
  355. <DisplayName("Text Font")> _
  356. Public Property TF() As Font
  357. Get
  358. Return TextFont
  359. End Get
  360. Set(value As Font)
  361. TextFont = value
  362. End Set
  363. End Property
  364. Dim X, Y As Integer
  365.  
  366. Protected Overrides Sub OnPaint(e As PaintEventArgs)
  367. Dim bm As New Bitmap(Me.Width, Me.Height)
  368. Dim g As Graphics = Graphics.FromImage(bm)
  369. ' Dim rect As New Rectangle(0, 0, Me.Width, (Me.Height - 35))
  370. ' Dim brush As New LinearGradientBrush(rect, Color.FromArgb(250, 250, 250), Color.FromArgb(206, 206, 206), 90.0!)
  371. 'Begin
  372. 'Main part
  373. If Clickedd = True Then
  374. g.DrawRectangle(New Pen(PopColor), 0, 0, Me.Width, Me.Height - 7)
  375. g.FillRectangle(New SolidBrush(PopColor), 0, 0, Me.Width, Me.Height - 7)
  376. Else
  377. If Inner = True Then
  378. g.DrawRectangle(New Pen(HoverColor), 0, 0, Me.Width, Me.Height - 7)
  379. g.FillRectangle(New SolidBrush(HoverColor), 0, 0, Me.Width, Me.Height - 7)
  380. Else
  381. g.DrawRectangle(New Pen(MainColor), 0, 0, Me.Width, Me.Height - 7)
  382. g.FillRectangle(New SolidBrush(MainColor), 0, 0, Me.Width, Me.Height - 7)
  383. End If
  384. End If
  385. 'Bottom part
  386. g.DrawRectangle(New Pen(PopColor), 0, Me.Height - 7, Me.Width, Me.Height - 7)
  387. g.FillRectangle(New SolidBrush(PopColor), 0, Me.Height - 7, Me.Width, Me.Height - Me.Height + 7)
  388. 'Text
  389. Dim rect = New Rectangle(0, 0, Me.Width, Me.Height - 7)
  390. g.DrawString("Read More", TextFont, New SolidBrush(TextColor), rect, New StringFormat With {.Alignment = StringAlignment.Center, .LineAlignment = StringAlignment.Center})
  391. 'End
  392. Clickedd = False
  393. e.Graphics.DrawImage(DirectCast(bm.Clone(), Bitmap), 0, 0)
  394. g.Dispose()
  395. bm.Dispose()
  396. MyBase.OnPaint(e)
  397. End Sub
  398. #Region "ThemeDraggable"
  399. Public Clickedd As Boolean = False
  400.  
  401. Public Inner As Boolean = False
  402. Protected Overrides Sub OnMouseDown(e As MouseEventArgs)
  403.  
  404. Dim clickRect As New Rectangle(0, 0, Me.Width, Me.Height)
  405. If clickRect.Contains(New Point(e.X, e.Y)) Then
  406. Clickedd = True
  407. RaiseEvent Clicked()
  408. End If
  409. '
  410.  
  411. MyBase.OnMouseDown(e)
  412. End Sub
  413.  
  414. Protected Overrides Sub OnMouseUp(e As MouseEventArgs)
  415.  
  416. MyBase.OnMouseUp(e)
  417. End Sub
  418.  
  419. Private mouseX As Integer
  420. Private mouseY As Integer
  421. Protected Overrides Sub OnMouseMove(e As MouseEventArgs)
  422. Dim clickRect As New Rectangle(2, 2, Me.Width - 2, Me.Height - 2)
  423. If clickRect.Contains(New Point(e.X, e.Y)) Then
  424. Inner = True
  425. Else
  426. Inner = False
  427. End If
  428. mouseX = e.X
  429. mouseY = e.Y
  430.  
  431. MyBase.OnMouseMove(e)
  432. Invalidate()
  433. End Sub
  434.  
  435. #End Region
  436. End Class
  437. <DefaultEvent("Scroll")> _
  438. Class NSVScrollBar
  439. Inherits Control
  440. 'Made by the awesome and great AeonHack
  441. Event Scroll(ByVal sender As Object)
  442.  
  443. Private _Minimum As Integer
  444. Property Minimum() As Integer
  445. Get
  446. Return _Minimum
  447. End Get
  448. Set(ByVal value As Integer)
  449. If value < 0 Then
  450. Throw New Exception("Property value is not valid.")
  451. End If
  452.  
  453. _Minimum = value
  454. If value > _Value Then _Value = value
  455. If value > _Maximum Then _Maximum = value
  456.  
  457. InvalidateLayout()
  458. End Set
  459. End Property
  460.  
  461. Private _Maximum As Integer = 100
  462. Property Maximum() As Integer
  463. Get
  464. Return _Maximum
  465. End Get
  466. Set(ByVal value As Integer)
  467. If value < 1 Then value = 1
  468.  
  469. _Maximum = value
  470. If value < _Value Then _Value = value
  471. If value < _Minimum Then _Minimum = value
  472.  
  473. InvalidateLayout()
  474. End Set
  475. End Property
  476.  
  477. Private _Value As Integer
  478. Property Value() As Integer
  479. Get
  480. If Not ShowThumb Then Return _Minimum
  481. Return _Value
  482. End Get
  483. Set(ByVal value As Integer)
  484. If value = _Value Then Return
  485.  
  486. If value > _Maximum OrElse value < _Minimum Then
  487. Throw New Exception("Property value is not valid.")
  488. End If
  489.  
  490. _Value = value
  491. InvalidatePosition()
  492.  
  493. RaiseEvent Scroll(Me)
  494. End Set
  495. End Property
  496.  
  497. Property _Percent As Double
  498. Public ReadOnly Property Percent As Double
  499. Get
  500. If Not ShowThumb Then Return 0
  501. Return GetProgress()
  502. End Get
  503. End Property
  504.  
  505. Private _SmallChange As Integer = 1
  506. Public Property SmallChange() As Integer
  507. Get
  508. Return _SmallChange
  509. End Get
  510. Set(ByVal value As Integer)
  511. If value < 1 Then
  512. Throw New Exception("Property value is not valid.")
  513. End If
  514.  
  515. _SmallChange = value
  516. End Set
  517. End Property
  518.  
  519. Private _LargeChange As Integer = 10
  520. Public Property LargeChange() As Integer
  521. Get
  522. Return _LargeChange
  523. End Get
  524. Set(ByVal value As Integer)
  525. If value < 1 Then
  526. Throw New Exception("Property value is not valid.")
  527. End If
  528.  
  529. _LargeChange = value
  530. End Set
  531. End Property
  532.  
  533. Private ButtonSize As Integer = 16
  534. Private ThumbSize As Integer = 24 ' 14 minimum
  535.  
  536. Private TSA As Rectangle
  537. Private BSA As Rectangle
  538. Private Shaft As Rectangle
  539. Private Thumb As Rectangle
  540.  
  541. Private ShowThumb As Boolean
  542. Private ThumbDown As Boolean
  543.  
  544. Sub New()
  545. SetStyle(DirectCast(139286, ControlStyles), True)
  546. SetStyle(ControlStyles.Selectable, False)
  547.  
  548. Width = 18
  549.  
  550. B1 = New SolidBrush(Color.FromArgb(27, 132, 188))
  551. B2 = New SolidBrush(Color.FromArgb(33, 159, 225))
  552.  
  553. P1 = New Pen(Color.FromArgb(235, 235, 235))
  554. P2 = New Pen(Color.FromArgb(165, 165, 165))
  555. P3 = New Pen(Color.FromArgb(155, 155, 155))
  556. P4 = New Pen(Color.FromArgb(140, 140, 40))
  557. End Sub
  558.  
  559. Private GP1, GP2, GP3, GP4 As GraphicsPath
  560.  
  561. Private P1, P2, P3, P4 As Pen
  562. Private B1, B2 As SolidBrush
  563.  
  564. Dim I1 As Integer
  565.  
  566. Protected Overrides Sub OnPaint(e As System.Windows.Forms.PaintEventArgs)
  567. Dim bm As New Bitmap(Me.Width, Me.Height)
  568. Dim g As Graphics = Graphics.FromImage(bm)
  569. G = e.Graphics
  570. G.Clear(Color.FromArgb(242, 242, 242))
  571.  
  572. GP1 = DrawArrow(3, 6, False)
  573. GP2 = DrawArrow(4, 7, False)
  574.  
  575. G.FillPath(B1, GP2)
  576. G.FillPath(B2, GP1)
  577.  
  578. GP3 = DrawArrow(3, Height - 11, True)
  579. GP4 = DrawArrow(4, Height - 10, True)
  580.  
  581. G.FillPath(B1, GP4)
  582. G.FillPath(B2, GP3)
  583.  
  584. If ShowThumb Then
  585. G.FillRectangle(B1, Thumb)
  586. G.DrawRectangle(P1, Thumb)
  587. G.DrawRectangle(P2, Thumb.X + 1, Thumb.Y + 1, Thumb.Width - 2, Thumb.Height - 2)
  588.  
  589. Dim Y As Integer
  590. Dim LY As Integer = Thumb.Y + (Thumb.Height \ 2) - 3
  591.  
  592. For I As Integer = 0 To 2
  593. Y = LY + (I * 3)
  594.  
  595. G.DrawLine(P1, Thumb.X + 5, Y, Thumb.Right - 5, Y)
  596. G.DrawLine(P2, Thumb.X + 5, Y + 1, Thumb.Right - 5, Y + 1)
  597. Next
  598. End If
  599.  
  600. G.DrawRectangle(P3, 0, 0, Width - 1, Height - 1)
  601. ' G.DrawRectangle(P4, 1, 1, Width - 3, Height - 3)
  602. End Sub
  603.  
  604. Private Function DrawArrow(x As Integer, y As Integer, flip As Boolean) As GraphicsPath
  605. Dim GP As New GraphicsPath()
  606.  
  607. Dim W As Integer = 9
  608. Dim H As Integer = 5
  609.  
  610. If flip Then
  611. GP.AddLine(x + 1, y, x + W + 1, y)
  612. GP.AddLine(x + W, y, x + H, y + H - 1)
  613. Else
  614. GP.AddLine(x, y + H, x + W, y + H)
  615. GP.AddLine(x + W, y + H, x + H, y)
  616. End If
  617.  
  618. GP.CloseFigure()
  619. Return GP
  620. End Function
  621.  
  622. Protected Overrides Sub OnSizeChanged(e As EventArgs)
  623. InvalidateLayout()
  624. End Sub
  625.  
  626. Private Sub InvalidateLayout()
  627. TSA = New Rectangle(0, 0, Width, ButtonSize)
  628. BSA = New Rectangle(0, Height - ButtonSize, Width, ButtonSize)
  629. Shaft = New Rectangle(0, TSA.Bottom + 1, Width, Height - (ButtonSize * 2) - 1)
  630.  
  631. ShowThumb = ((_Maximum - _Minimum) > Shaft.Height)
  632.  
  633. If ShowThumb Then
  634. 'ThumbSize = Math.Max(0, 14) 'TODO: Implement this.
  635. Thumb = New Rectangle(1, 0, Width - 3, ThumbSize)
  636. End If
  637.  
  638. RaiseEvent Scroll(Me)
  639. InvalidatePosition()
  640. End Sub
  641.  
  642. Private Sub InvalidatePosition()
  643. Thumb.Y = CInt(GetProgress() * (Shaft.Height - ThumbSize)) + TSA.Height
  644. Invalidate()
  645. End Sub
  646.  
  647. Protected Overrides Sub OnMouseDown(ByVal e As MouseEventArgs)
  648. If e.Button = Windows.Forms.MouseButtons.Left AndAlso ShowThumb Then
  649. If TSA.Contains(e.Location) Then
  650. I1 = _Value - _SmallChange
  651. ElseIf BSA.Contains(e.Location) Then
  652. I1 = _Value + _SmallChange
  653. Else
  654. If Thumb.Contains(e.Location) Then
  655. ThumbDown = True
  656. MyBase.OnMouseDown(e)
  657. Return
  658. Else
  659. If e.Y < Thumb.Y Then
  660. I1 = _Value - _LargeChange
  661. Else
  662. I1 = _Value + _LargeChange
  663. End If
  664. End If
  665. End If
  666.  
  667. Value = Math.Min(Math.Max(I1, _Minimum), _Maximum)
  668. InvalidatePosition()
  669. End If
  670.  
  671. MyBase.OnMouseDown(e)
  672. End Sub
  673.  
  674. Protected Overrides Sub OnMouseMove(ByVal e As MouseEventArgs)
  675. If ThumbDown AndAlso ShowThumb Then
  676. Dim ThumbPosition As Integer = e.Y - TSA.Height - (ThumbSize \ 2)
  677. Dim ThumbBounds As Integer = Shaft.Height - ThumbSize
  678.  
  679. I1 = CInt((ThumbPosition / ThumbBounds) * (_Maximum - _Minimum)) + _Minimum
  680.  
  681. Value = Math.Min(Math.Max(I1, _Minimum), _Maximum)
  682. InvalidatePosition()
  683. End If
  684.  
  685. MyBase.OnMouseMove(e)
  686. End Sub
  687.  
  688. Protected Overrides Sub OnMouseUp(ByVal e As MouseEventArgs)
  689. ThumbDown = False
  690. MyBase.OnMouseUp(e)
  691. End Sub
  692.  
  693. Private Function GetProgress() As Double
  694. Return (_Value - _Minimum) / (_Maximum - _Minimum)
  695. End Function
  696.  
  697. End Class
  698.  
  699. Partial Public Class FlatGroupBox
  700. Inherits Panel
  701. Property Downsize As Size = New Size(386, 146)
  702. Property UporDown As Boolean = True
  703. Property OutBorderColor As Color = Color.FromArgb(229, 229, 229)
  704. Property InBorderColor As Color = Color.FromArgb(219, 219, 219)
  705. Property HeaderColor As Color = Color.FromArgb(255, 255, 255)
  706. Property BoxColor As Color = Color.FromArgb(242, 242, 242)
  707. Property OddColor As Color = Color.FromArgb(27, 132, 188)
  708. Property PopOddColor As Color = Color.FromArgb(17, 122, 178)
  709. Property _text As String = "Box"
  710. Sub New()
  711. Me.Padding = New Padding(2, 37, 2, 2)
  712. End Sub
  713. Private Sub FlatGroupBox_Paint(sender As Object, e As PaintEventArgs) Handles Me.Paint
  714. e.Graphics.Clear(BoxColor)
  715. e.Graphics.DrawRectangle(New Pen(InBorderColor), New Rectangle(0, 35, Me.Width - 2, Me.Height - 36))
  716. e.Graphics.DrawRectangle(New Pen(OutBorderColor), New Rectangle(0, 36, Me.Width - 3, Me.Height - 37))
  717. e.Graphics.FillRectangle(New SolidBrush(HeaderColor), New Rectangle(0, 0, Me.Width, 35))
  718. If UporDown = True Then
  719. e.Graphics.FillRectangle(New SolidBrush(OddColor), New Rectangle(Me.Width - 27, 22, 20, 6))
  720. e.Graphics.FillRectangle(New SolidBrush(PopOddColor), New Rectangle(Me.Width - 27, 26, 20, 2))
  721. e.Graphics.FillRectangle(New SolidBrush(OddColor), New Rectangle(Me.Width - 27, 14, 20, 6))
  722. e.Graphics.FillRectangle(New SolidBrush(PopOddColor), New Rectangle(Me.Width - 27, 18, 20, 2))
  723. e.Graphics.FillRectangle(New SolidBrush(OddColor), New Rectangle(Me.Width - 27, 6, 20, 6))
  724. e.Graphics.FillRectangle(New SolidBrush(PopOddColor), New Rectangle(Me.Width - 27, 10, 20, 2))
  725. Me.Size = Downsize
  726. Else
  727. e.Graphics.FillRectangle(New SolidBrush(InBorderColor), New Rectangle(Me.Width - 27, 22, 20, 6))
  728. e.Graphics.FillRectangle(New SolidBrush(OutBorderColor), New Rectangle(Me.Width - 27, 26, 20, 2))
  729. e.Graphics.FillRectangle(New SolidBrush(InBorderColor), New Rectangle(Me.Width - 27, 14, 20, 6))
  730. e.Graphics.FillRectangle(New SolidBrush(OutBorderColor), New Rectangle(Me.Width - 27, 18, 20, 2))
  731. e.Graphics.FillRectangle(New SolidBrush(InBorderColor), New Rectangle(Me.Width - 27, 6, 20, 6))
  732. e.Graphics.FillRectangle(New SolidBrush(OutBorderColor), New Rectangle(Me.Width - 27, 10, 20, 2))
  733. Me.Size = New Size(Me.Width, 36)
  734. End If
  735. e.Graphics.DrawString(_text, New Font("Arial", 12.5, FontStyle.Regular), New SolidBrush(Color.FromArgb(130, 130, 130)), 5, 8)
  736. End Sub
  737. Protected Overrides Sub OnMouseDown(e As MouseEventArgs)
  738.  
  739. Dim clickRect As New Rectangle(Me.Width - 27, 10, 20, 20)
  740. If clickRect.Contains(New Point(e.X, e.Y)) Then
  741. UporDown = Not UporDown
  742. Me.Refresh()
  743. End If
  744. '
  745.  
  746. MyBase.OnMouseDown(e)
  747. End Sub
  748. End Class
  749. Partial Public Class FlatListbox
  750. Inherits Panel
  751. Public Event SelectedItem(i As Integer)
  752. Property OutBorderColor As Color = Color.FromArgb(229, 229, 229)
  753. Property InBorderColor As Color = Color.FromArgb(219, 219, 219)
  754. Property BoxColor As Color = Color.FromArgb(242, 242, 242)
  755. Property OddColor As Color = Color.FromArgb(27, 132, 188)
  756. Property PopOddColor As Color = Color.FromArgb(17, 122, 178)
  757. Private VS As NSVScrollBar
  758. Protected Overrides Sub OnSizeChanged(e As EventArgs)
  759. InvalidateLayout()
  760. MyBase.OnSizeChanged(e)
  761. End Sub
  762.  
  763. Private Sub HandleScroll(sender As Object)
  764. Invalidate()
  765. End Sub
  766.  
  767. Private Sub InvalidateScroll()
  768. VS.Maximum = (_Items.Count * 24)
  769. Invalidate()
  770. End Sub
  771.  
  772. Private Sub InvalidateLayout()
  773. VS.Location = New Point(Width - VS.Width + 2, 1)
  774. VS.Size = New Size(18, Height - 2)
  775.  
  776. Invalidate()
  777. End Sub
  778. Sub New()
  779. SetStyle(DirectCast(139286, ControlStyles), True)
  780. SetStyle(ControlStyles.Selectable, True)
  781.  
  782.  
  783.  
  784. VS = New NSVScrollBar
  785. VS.SmallChange = 24
  786. VS.LargeChange = 24
  787.  
  788. AddHandler VS.Scroll, AddressOf HandleScroll
  789. AddHandler VS.MouseDown, AddressOf VS_MouseDown
  790. Controls.Add(VS)
  791.  
  792. InvalidateLayout()
  793. End Sub
  794. Private Sub VS_MouseDown(sender As Object, e As MouseEventArgs)
  795. Focus()
  796. Dim Offset As Integer = CInt(VS.Percent * (VS.Maximum - (Height - (24 * 2))))
  797. Dim Index As Integer = ((e.Y + Offset - 24) \ 24)
  798. End Sub
  799. Protected Overrides Sub OnMouseWheel(e As MouseEventArgs)
  800. Dim Move As Integer = -((e.Delta * SystemInformation.MouseWheelScrollLines \ 120) * (24 \ 2))
  801.  
  802. Dim Value As Integer = Math.Max(Math.Min(VS.Value + Move, VS.Maximum), VS.Minimum)
  803. VS.Value = Value
  804.  
  805. MyBase.OnMouseWheel(e)
  806. End Sub
  807. Public Class ItemCollection
  808. Inherits List(Of Item)
  809. Private Parent As FlatListbox
  810. Public Sub New(Parent As FlatListbox)
  811. Me.Parent = Parent
  812.  
  813. End Sub
  814. Public Shadows Sub Add(Item As Item)
  815. MyBase.Add(Item)
  816. Parent.InvalidateScroll()
  817. End Sub
  818. Public Shadows Sub AddRange(Range As List(Of Item))
  819. MyBase.AddRange(Range)
  820. Parent.InvalidateScroll()
  821. End Sub
  822. Public Shadows Sub Clear()
  823. MyBase.Clear()
  824. Parent.InvalidateScroll()
  825. End Sub
  826. Public Shadows Sub Remove(Item As Item)
  827. MyBase.Remove(Item)
  828. Parent.InvalidateScroll()
  829. End Sub
  830. Public Shadows Sub RemoveAt(Index As Integer)
  831. MyBase.RemoveAt(Index)
  832. Parent.InvalidateScroll()
  833. End Sub
  834. Public Shadows Sub RemoveAll(Predicate As System.Predicate(Of Item))
  835. MyBase.RemoveAll(Predicate)
  836. Parent.InvalidateScroll()
  837. End Sub
  838. Public Shadows Sub RemoveRange(Index As Integer, Count As Integer)
  839. MyBase.RemoveRange(Index, Count)
  840. Parent.InvalidateScroll()
  841. End Sub
  842.  
  843. End Class
  844. Public Class Item
  845. Property Text As String
  846. Property OddColor As Color = Color.FromArgb(37, 142, 198)
  847. Property PopOddColor As Color = Color.FromArgb(17, 122, 178)
  848. Property Index As Integer = 0
  849. Property locy As Integer = 0
  850. Property Selected As Boolean = False
  851. Protected UniqueId As Guid
  852. Sub New()
  853. UniqueId = Guid.NewGuid()
  854. End Sub
  855. Public Overrides Function ToString() As String
  856. Return Text
  857. End Function
  858.  
  859. Public Overrides Function Equals(obj As Object) As Boolean
  860. If TypeOf obj Is Item Then
  861. Return (DirectCast(obj, Item).UniqueId = UniqueId)
  862. End If
  863. Return False
  864. End Function
  865.  
  866. End Class
  867. Public _Items As New ItemCollection(Me)
  868. <DesignerSerializationVisibility(DesignerSerializationVisibility.Content)> _
  869. Public Property Items As ItemCollection
  870. Get
  871. Return _Items
  872. End Get
  873. Set(ByVal value As ItemCollection)
  874. _Items = value
  875. End Set
  876. End Property
  877.  
  878. Private Sub FlatListbox_Paint(sender As Object, e As PaintEventArgs) Handles Me.Paint
  879. Dim Offset As Integer = CInt(VS.Percent * (VS.Maximum - (Height - (24 * 2))))
  880. e.Graphics.Clear(BoxColor)
  881. e.Graphics.DrawRectangle(New Pen(InBorderColor), New Rectangle(1, 1, Me.Width - 3, Me.Height - 3))
  882. e.Graphics.DrawRectangle(New Pen(OutBorderColor), New Rectangle(0, 0, Me.Width - 2, Me.Height - 2))
  883.  
  884. Dim y As Integer = 4
  885. For Each Item As Item In _Items
  886.  
  887. y = 24 * Item.Index
  888. If Not Item.Selected = True Then
  889. Item.locy = y
  890. Dim rect = New Rectangle(2, y - Offset, Me.Width - 4, 24)
  891. e.Graphics.FillRectangle(New SolidBrush(Color.FromArgb(255, 255, 255)), rect)
  892. rect = New Rectangle(2, y + 20 - Offset, Me.Width - 4, 4)
  893. e.Graphics.FillRectangle(New SolidBrush(Color.FromArgb(232, 232, 232)), rect)
  894. e.Graphics.DrawString(Item.Text, New Font("Arial", 9.5, FontStyle.Regular), New SolidBrush(Color.FromArgb(130, 130, 130)), 2, y + 4 - Offset)
  895. Else
  896. Dim rect = New Rectangle(2, y - Offset, Me.Width - 4, 24)
  897. e.Graphics.FillRectangle(New SolidBrush(OddColor), rect)
  898. rect = New Rectangle(2, y + 20 - Offset, Me.Width - 4, 4)
  899. e.Graphics.FillRectangle(New SolidBrush(PopOddColor), rect)
  900. e.Graphics.DrawString(Item.Text, New Font("Arial", 9.5, FontStyle.Regular), New SolidBrush(Color.White), 2, y + 4 - Offset)
  901. End If
  902. Next
  903. End Sub
  904. 'Example
  905. Public Function SelectedItemIndex()
  906. For Each Item As Item In _Items
  907. If Item.Selected = True Then
  908. Return Item.Index
  909. End If
  910. Next
  911. End Function
  912. #Region "ThemeDraggable"
  913. Protected Overrides Sub OnMouseDown(e As MouseEventArgs)
  914. Dim y As Integer = 3
  915. Dim Offset As Integer = CInt(VS.Percent * (VS.Maximum - (Height - (24 * 2))))
  916. For Each Item As Item In _Items
  917. y = 24 * Item.Index
  918. Dim rect = New Rectangle(2, y - Offset, Me.Width - 4, 24)
  919. If Item.locy = y Then
  920. If rect.Contains(mouseX, mouseY) Then
  921. Item.Selected = Not Item.Selected
  922. RaiseEvent SelectedItem(Item.Index)
  923. Else
  924. Item.Selected = False
  925. End If
  926. Else
  927. Item.Selected = False
  928. End If
  929. Next
  930. '
  931.  
  932. MyBase.OnMouseDown(e)
  933. End Sub
  934.  
  935. Protected Overrides Sub OnMouseUp(e As MouseEventArgs)
  936.  
  937. MyBase.OnMouseUp(e)
  938. End Sub
  939.  
  940. Private mouseX As Integer
  941. Private mouseY As Integer
  942. Protected Overrides Sub OnMouseMove(e As MouseEventArgs)
  943.  
  944. mouseX = e.X
  945. mouseY = e.Y
  946.  
  947. MyBase.OnMouseMove(e)
  948. Invalidate()
  949. End Sub
  950.  
  951. #End Region
  952. End Class
  953. Module DesignFunctions
  954. Function ToBrush(ByVal A As Integer, ByVal R As Integer, ByVal G As Integer, ByVal B As Integer) As Brush
  955. Return ToBrush(Color.FromArgb(A, R, G, B))
  956. End Function
  957. Function ToBrush(ByVal R As Integer, ByVal G As Integer, ByVal B As Integer) As Brush
  958. Return ToBrush(Color.FromArgb(R, G, B))
  959. End Function
  960. Function ToBrush(ByVal A As Integer, ByVal C As Color) As Brush
  961. Return ToBrush(Color.FromArgb(A, C))
  962. End Function
  963. Function ToBrush(ByVal Pen As Pen) As Brush
  964. Return ToBrush(Pen.Color)
  965. End Function
  966. Function ToBrush(ByVal Color As Color) As Brush
  967. Return New SolidBrush(Color)
  968. End Function
  969. Function ToPen(ByVal A As Integer, ByVal R As Integer, ByVal G As Integer, ByVal B As Integer) As Pen
  970. Return ToPen(Color.FromArgb(A, R, G, B))
  971. End Function
  972. Function ToPen(ByVal R As Integer, ByVal G As Integer, ByVal B As Integer) As Pen
  973. Return ToPen(Color.FromArgb(R, G, B))
  974. End Function
  975. Function ToPen(ByVal A As Integer, ByVal C As Color) As Pen
  976. Return ToPen(Color.FromArgb(A, C))
  977. End Function
  978. Function ToPen(ByVal Color As Color) As Pen
  979. Return ToPen(New SolidBrush(Color))
  980. End Function
  981. Function ToPen(ByVal Brush As SolidBrush) As Pen
  982. Return New Pen(Brush)
  983. End Function
  984.  
  985. Class CornerStyle
  986. Public TopLeft As Boolean
  987. Public TopRight As Boolean
  988. Public BottomLeft As Boolean
  989. Public BottomRight As Boolean
  990. End Class
  991.  
  992. Public Function AdvRect(ByVal Rectangle As Rectangle, ByVal CornerStyle As CornerStyle, ByVal Curve As Integer) As GraphicsPath
  993. AdvRect = New GraphicsPath()
  994. Dim ArcRectangleWidth As Integer = Curve * 2
  995.  
  996. If CornerStyle.TopLeft Then
  997. AdvRect.AddArc(New Rectangle(Rectangle.X, Rectangle.Y, ArcRectangleWidth, ArcRectangleWidth), -180, 90)
  998. Else
  999. AdvRect.AddLine(Rectangle.X, Rectangle.Y, Rectangle.X + ArcRectangleWidth, Rectangle.Y)
  1000. End If
  1001.  
  1002. If CornerStyle.TopRight Then
  1003. AdvRect.AddArc(New Rectangle(Rectangle.Width - ArcRectangleWidth + Rectangle.X, Rectangle.Y, ArcRectangleWidth, ArcRectangleWidth), -90, 90)
  1004. Else
  1005. AdvRect.AddLine(Rectangle.X + Rectangle.Width, Rectangle.Y, Rectangle.X + Rectangle.Width, Rectangle.Y + ArcRectangleWidth)
  1006. End If
  1007.  
  1008. If CornerStyle.BottomRight Then
  1009. AdvRect.AddArc(New Rectangle(Rectangle.Width - ArcRectangleWidth + Rectangle.X, Rectangle.Height - ArcRectangleWidth + Rectangle.Y, ArcRectangleWidth, ArcRectangleWidth), 0, 90)
  1010. Else
  1011. AdvRect.AddLine(Rectangle.X + Rectangle.Width, Rectangle.Y + Rectangle.Height, Rectangle.X + Rectangle.Width - ArcRectangleWidth, Rectangle.Y + Rectangle.Height)
  1012. End If
  1013.  
  1014. If CornerStyle.BottomLeft Then
  1015. AdvRect.AddArc(New Rectangle(Rectangle.X, Rectangle.Height - ArcRectangleWidth + Rectangle.Y, ArcRectangleWidth, ArcRectangleWidth), 90, 90)
  1016. Else
  1017. AdvRect.AddLine(Rectangle.X, Rectangle.Y + Rectangle.Height, Rectangle.X, Rectangle.Y + Rectangle.Height - ArcRectangleWidth)
  1018. End If
  1019.  
  1020. AdvRect.CloseAllFigures()
  1021.  
  1022. Return AdvRect
  1023. End Function
  1024.  
  1025. Public Function RoundRect(ByVal Rectangle As Rectangle, ByVal Curve As Integer) As GraphicsPath
  1026. RoundRect = New GraphicsPath()
  1027. Dim ArcRectangleWidth As Integer = Curve * 2
  1028. RoundRect.AddArc(New Rectangle(Rectangle.X, Rectangle.Y, ArcRectangleWidth, ArcRectangleWidth), -180, 90)
  1029. RoundRect.AddArc(New Rectangle(Rectangle.Width - ArcRectangleWidth + Rectangle.X, Rectangle.Y, ArcRectangleWidth, ArcRectangleWidth), -90, 90)
  1030. RoundRect.AddArc(New Rectangle(Rectangle.Width - ArcRectangleWidth + Rectangle.X, Rectangle.Height - ArcRectangleWidth + Rectangle.Y, ArcRectangleWidth, ArcRectangleWidth), 0, 90)
  1031. RoundRect.AddArc(New Rectangle(Rectangle.X, Rectangle.Height - ArcRectangleWidth + Rectangle.Y, ArcRectangleWidth, ArcRectangleWidth), 90, 90)
  1032. RoundRect.AddLine(New Point(Rectangle.X, Rectangle.Height - ArcRectangleWidth + Rectangle.Y), New Point(Rectangle.X, ArcRectangleWidth + Rectangle.Y))
  1033. RoundRect.CloseAllFigures()
  1034. Return RoundRect
  1035. End Function
  1036.  
  1037. 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
  1038. Return RoundRect(New Rectangle(X, Y, Width, Height), Curve)
  1039. End Function
  1040.  
  1041. Class PillStyle
  1042. Public Left As Boolean
  1043. Public Right As Boolean
  1044. End Class
  1045.  
  1046. Public Function Pill(ByVal Rectangle As Rectangle, ByVal PillStyle As PillStyle) As GraphicsPath
  1047. Pill = New GraphicsPath()
  1048.  
  1049. If PillStyle.Left Then
  1050. Pill.AddArc(New Rectangle(Rectangle.X, Rectangle.Y, Rectangle.Height, Rectangle.Height), -270, 180)
  1051. Else
  1052. Pill.AddLine(Rectangle.X, Rectangle.Y + Rectangle.Height, Rectangle.X, Rectangle.Y)
  1053. End If
  1054.  
  1055. If PillStyle.Right Then
  1056. Pill.AddArc(New Rectangle(Rectangle.X + Rectangle.Width - Rectangle.Height, Rectangle.Y, Rectangle.Height, Rectangle.Height), -90, 180)
  1057. Else
  1058. Pill.AddLine(Rectangle.X + Rectangle.Width, Rectangle.Y, Rectangle.X + Rectangle.Width, Rectangle.Y + Rectangle.Height)
  1059. End If
  1060.  
  1061. Pill.CloseAllFigures()
  1062.  
  1063. Return Pill
  1064. End Function
  1065.  
  1066. Public Function Pill(ByVal X As Integer, ByVal Y As Integer, ByVal Width As Integer, ByVal Height As Integer, ByVal PillStyle As PillStyle)
  1067. Return Pill(New Rectangle(X, Y, Width, Height), PillStyle)
  1068. End Function
  1069.  
  1070. End Module
  1071. Class ThemedTrackBar
  1072. Inherits Control
  1073. 'Base or Template used was from Tedd
  1074. #Region "Properties"
  1075. Dim _Maximum As Integer = 10
  1076. Public Property Maximum() As Integer
  1077. Get
  1078. Return _Maximum
  1079. End Get
  1080. Set(ByVal value As Integer)
  1081. If value > 0 Then _Maximum = value
  1082. If value < _Value Then _Value = value
  1083. Invalidate()
  1084. End Set
  1085. End Property
  1086.  
  1087. Event ValueChanged()
  1088. Dim _Value As Integer = 0
  1089. Public Property Value() As Integer
  1090. Get
  1091. Return _Value
  1092. End Get
  1093. Set(ByVal value As Integer)
  1094.  
  1095. Select Case value
  1096. Case Is = _Value
  1097. Exit Property
  1098. Case Is < 0
  1099. _Value = 0
  1100. Case Is > _Maximum
  1101. _Value = _Maximum
  1102. Case Else
  1103. _Value = value
  1104. End Select
  1105.  
  1106. Invalidate()
  1107. RaiseEvent ValueChanged()
  1108. End Set
  1109. End Property
  1110. #End Region
  1111.  
  1112. Sub New()
  1113. Me.SetStyle(ControlStyles.DoubleBuffer Or _
  1114. ControlStyles.AllPaintingInWmPaint Or _
  1115. ControlStyles.ResizeRedraw Or _
  1116. ControlStyles.UserPaint Or _
  1117. ControlStyles.Selectable Or _
  1118. ControlStyles.SupportsTransparentBackColor, True)
  1119. End Sub
  1120.  
  1121. Dim CaptureM As Boolean = False
  1122. Dim Bar As Rectangle = New Rectangle(0, 10, Width - 1, Height - 21)
  1123. Dim Track As Size = New Size(20, 20)
  1124.  
  1125. Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
  1126. MyBase.OnPaint(e)
  1127. Dim G As Graphics = e.Graphics
  1128. Bar = New Rectangle(10, 10, Width - 21, Height - 21)
  1129. G.Clear(Parent.FindForm.BackColor)
  1130. G.SmoothingMode = SmoothingMode.AntiAlias
  1131.  
  1132. 'Background
  1133. Dim BackLinear As LinearGradientBrush = New LinearGradientBrush(New Point(0, CInt((Height / 2) - 4)), New Point(0, CInt((Height / 2) + 4)), Color.FromArgb(65, 65, 65), Color.FromArgb(65, 65, 65))
  1134. G.FillPath(BackLinear, RoundRect(0, CInt((Height / 2) - 4), Width - 1, 8, 3))
  1135. ' G.DrawPath(ToPen(50, Color.Black), RoundRect(0, CInt((Height / 2) - 4), Width - 1, 8, 3))
  1136. BackLinear.Dispose()
  1137. G.FillPath(New SolidBrush(Color.FromArgb(27, 132, 188)), RoundRect(0, CInt((Height / 2) - 4), Bar.X + CInt(Bar.Width * (Value / Maximum)) - CInt(Track.Width / 2) + 9, 8, 3))
  1138.  
  1139. 'Fill
  1140. ' G.FillPath(New LinearGradientBrush(New Point(1, CInt((Height / 2) - 4)), New Point(1, CInt((Height / 2) + 4)), Color.FromArgb(250, 200, 70), Color.FromArgb(250, 160, 40)), RoundRect(1, CInt((Height / 2) - 4), CInt(Bar.Width * (Value / Maximum)) + CInt(Track.Width / 2), 8, 3))
  1141. ' G.DrawPath(ToPen(100, Color.White), RoundRect(2, CInt((Height / 2) - 2), CInt(Bar.Width * (Value / Maximum)) + CInt(Track.Width / 2), 4, 3))
  1142. G.SetClip(RoundRect(1, CInt((Height / 2) - 4), CInt(Bar.Width * (Value / Maximum)) + CInt(Track.Width / 2), 8, 3))
  1143. For i = 0 To CInt(Bar.Width * (Value / Maximum)) + CInt(Track.Width / 2) Step 10
  1144. 'G.FillEllipse(New SolidBrush(Color.FromArgb(27, 132, 188)), New Rectangle(New Point(i, CInt((Height / 2) - 10)), New Point(i - 10, CInt((Height / 2) + 10))))
  1145. Next
  1146. G.SetClip(New Rectangle(0, 0, Width, Height))
  1147.  
  1148. 'Button
  1149. If inner = True Then
  1150. G.FillEllipse(Brushes.White, New Rectangle(Bar.X + CInt(Bar.Width * (Value / Maximum)) - CInt(Track.Width / 2) + 3, Bar.Y + CInt((Bar.Height / 2)) - CInt(Track.Height / 2) + 3, Track.Width - 6, Track.Height - 6))
  1151. G.DrawEllipse(ToPen(50, Color.Black), New Rectangle(Bar.X + CInt(Bar.Width * (Value / Maximum)) - CInt(Track.Width / 2) + 3, Bar.Y + CInt((Bar.Height / 2)) - CInt(Track.Height / 2) + 3, Track.Width - 6, Track.Height - 6))
  1152. 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(25, 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))
  1153. Else
  1154. G.FillEllipse(Brushes.White, New Rectangle(Bar.X + CInt(Bar.Width * (Value / Maximum)) - CInt(Track.Width / 2) + 3, Bar.Y + CInt((Bar.Height / 2)) - CInt(Track.Height / 2) + 3, Track.Width - 6, Track.Height - 6))
  1155. G.DrawEllipse(ToPen(50, Color.Black), New Rectangle(Bar.X + CInt(Bar.Width * (Value / Maximum)) - CInt(Track.Width / 2) + 3, Bar.Y + CInt((Bar.Height / 2)) - CInt(Track.Height / 2) + 3, Track.Width - 6, Track.Height - 6))
  1156. End If
  1157. End Sub
  1158.  
  1159. Protected Overrides Sub OnHandleCreated(ByVal e As System.EventArgs)
  1160. Me.BackColor = Color.Transparent
  1161.  
  1162. MyBase.OnHandleCreated(e)
  1163. End Sub
  1164. Dim inner As Boolean = False
  1165. Protected Overrides Sub OnMouseDown(ByVal e As System.Windows.Forms.MouseEventArgs)
  1166. MyBase.OnMouseDown(e)
  1167. Dim mp = New Rectangle(New Point(e.Location.X, e.Location.Y), New Size(1, 1))
  1168. Dim Bar As Rectangle = New Rectangle(10, 10, Width - 21, Height - 21)
  1169. If New Rectangle(New Point(Bar.X + CInt(Bar.Width * (Value / Maximum)) - CInt(Track.Width / 2), 0), New Size(Track.Width, Height)).IntersectsWith(mp) Then
  1170. CaptureM = True
  1171. inner = True
  1172. End If
  1173. End Sub
  1174.  
  1175. Protected Overrides Sub OnMouseUp(ByVal e As System.Windows.Forms.MouseEventArgs)
  1176. MyBase.OnMouseUp(e)
  1177. CaptureM = False
  1178. inner = False
  1179. End Sub
  1180.  
  1181. Protected Overrides Sub OnMouseMove(ByVal e As System.Windows.Forms.MouseEventArgs)
  1182. MyBase.OnMouseMove(e)
  1183. If CaptureM Then
  1184. Dim mp As Point = New Point(e.X, e.Y)
  1185. Dim Bar As Rectangle = New Rectangle(10, 10, Width - 21, Height - 21)
  1186. Value = CInt(Maximum * ((mp.X - Bar.X) / Bar.Width))
  1187. End If
  1188. End Sub
  1189.  
  1190. Protected Overrides Sub OnMouseLeave(ByVal e As System.EventArgs)
  1191. MyBase.OnMouseLeave(e) : CaptureM = False
  1192. End Sub
  1193.  
  1194. End Class
Add Comment
Please, Sign In to add comment