Advanced System Core


SUBMITTED BY: Guest

DATE: June 5, 2014, 9:25 a.m.

FORMAT: Text only

SIZE: 24.5 kB

HITS: 1247

  1. Imports System.Drawing.Drawing2D
  2. Imports System.ComponentModel
  3. Module Drawing
  4. Public Function RoundRect(ByVal rect As Rectangle, ByVal slope As Integer) As GraphicsPath
  5. Dim gp As GraphicsPath = New GraphicsPath()
  6. Dim arcWidth As Integer = slope * 2
  7. gp.AddArc(New Rectangle(rect.X, rect.Y, arcWidth, arcWidth), -180, 90)
  8. gp.AddArc(New Rectangle(rect.Width - arcWidth + rect.X, rect.Y, arcWidth, arcWidth), -90, 90)
  9. gp.AddArc(New Rectangle(rect.Width - arcWidth + rect.X, rect.Height - arcWidth + rect.Y, arcWidth, arcWidth), 0, 90)
  10. gp.AddArc(New Rectangle(rect.X, rect.Height - arcWidth + rect.Y, arcWidth, arcWidth), 90, 90)
  11. gp.CloseAllFigures()
  12. Return gp
  13. End Function
  14. End Module
  15. Module Prevent
  16. Public Sub Prevent(ByVal g As Graphics, ByVal w As Integer, ByVal h As Integer)
  17. Dim txt As String = System.Text.Encoding.UTF8.GetString(Convert.FromBase64String("VGhlbWUlMjBjcmVhdGVkJTIwYnklMjBIYXdrJTIwSEY=")).Replace("%20", " ")
  18. Dim txtSize As SizeF = g.MeasureString(txt, New Font("Arial", 8))
  19. g.DrawString(txt, New Font("Arial", 8), New SolidBrush(Color.FromArgb(125, 125, 125)), New Point(w - txtSize.Width - 6, h - txtSize.Height - 4))
  20. End Sub
  21. End Module
  22. Class ascThemeContainer
  23. Inherits ContainerControl
  24. Private moveHeight As Integer = 38
  25. Private formCanMove As Boolean = False
  26. Private mouseX, mouseY As Integer
  27. Private overExit, overMin As Boolean
  28. Public Overrides Property Text() As String
  29. Get
  30. Return MyBase.Text
  31. End Get
  32. Set(ByVal value As String)
  33. MyBase.Text = value
  34. Invalidate()
  35. End Set
  36. End Property
  37. Sub New()
  38. SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.OptimizedDoubleBuffer Or _
  39. ControlStyles.UserPaint Or ControlStyles.ResizeRedraw, True)
  40. Dock = DockStyle.Fill
  41. Font = New Font("Arial", 12, FontStyle.Bold Or FontStyle.Italic)
  42. BackColor = Color.FromArgb(15, 15, 15)
  43. End Sub
  44. Protected Overrides Sub CreateHandle()
  45. MyBase.CreateHandle()
  46. FindForm.FormBorderStyle = FormBorderStyle.None
  47. If FindForm.TransparencyKey = Nothing Then FindForm.TransparencyKey = Color.Fuchsia
  48. End Sub
  49. Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
  50. MyBase.OnPaint(e)
  51. Dim G As Graphics = e.Graphics
  52. G.Clear(FindForm.TransparencyKey)
  53. Dim slope As Integer = 8
  54. Dim mainRect As New Rectangle(0, 0, Width - 1, Height - 1)
  55. Dim mainPath As GraphicsPath = RoundRect(mainRect, slope)
  56. G.FillPath(New SolidBrush(BackColor), mainPath)
  57. G.DrawPath(New Pen(Color.FromArgb(30, 35, 45)), mainPath)
  58. G.FillPath(New SolidBrush(Color.FromArgb(30, 30, 40)), RoundRect(New Rectangle(0, 0, Width - 1, moveHeight - slope), slope))
  59. G.FillRectangle(New SolidBrush(Color.FromArgb(30, 30, 40)), New Rectangle(0, moveHeight - (slope * 2), Width - 1, slope * 2))
  60. G.DrawLine(New Pen(Color.FromArgb(60, 60, 60)), New Point(1, moveHeight), New Point(Width - 2, moveHeight))
  61. G.SmoothingMode = SmoothingMode.HighQuality
  62. Dim textX As Integer = 6
  63. Dim textY As Integer = (moveHeight / 2) - (G.MeasureString(Text, Font).Height / 2) + 1
  64. Dim textSize As SizeF = G.MeasureString(Text, Font)
  65. Dim textRect As New Rectangle(textX, textY, textSize.Width, textSize.Height)
  66. Dim textBrush As New LinearGradientBrush(textRect, Color.FromArgb(185, 190, 195), Color.FromArgb(125, 125, 125), 90.0F)
  67. G.DrawString(Text, Font, textBrush, New Point(textX, textY))
  68. If overExit Then
  69. G.DrawString("r", New Font("Marlett", 12, FontStyle.Bold), New SolidBrush(Color.FromArgb(25, 100, 140)), New Point(Width - 27, 11))
  70. Else
  71. G.DrawString("r", New Font("Marlett", 12, FontStyle.Bold), New SolidBrush(Color.FromArgb(205, 210, 215)), New Point(Width - 27, 11))
  72. End If
  73. If overMin Then
  74. G.DrawString("0", New Font("Marlett", 12, FontStyle.Bold), New SolidBrush(Color.FromArgb(25, 100, 140)), New Point(Width - 47, 10))
  75. Else
  76. G.DrawString("0", New Font("Marlett", 12, FontStyle.Bold), New SolidBrush(Color.FromArgb(205, 210, 215)), New Point(Width - 47, 10))
  77. End If
  78. If DesignMode Then Prevent.Prevent(G, Width, Height)
  79. End Sub
  80. Protected Overrides Sub OnMouseMove(ByVal e As System.Windows.Forms.MouseEventArgs)
  81. MyBase.OnMouseMove(e)
  82. If formCanMove = True Then
  83. FindForm.Location = MousePosition - New Point(mouseX, mouseY)
  84. End If
  85. If e.Y > 11 AndAlso e.Y < 24 Then
  86. If e.X > Width - 23 AndAlso e.X < Width - 10 Then overExit = True Else overExit = False
  87. If e.X > Width - 44 AndAlso e.X < Width - 31 Then overMin = True Else overMin = False
  88. Else
  89. overExit = False
  90. overMin = False
  91. End If
  92. Invalidate()
  93. End Sub
  94. Protected Overrides Sub OnMouseDown(ByVal e As System.Windows.Forms.MouseEventArgs)
  95. MyBase.OnMouseDown(e)
  96. mouseX = e.X
  97. mouseY = e.Y
  98. If e.Y <= moveHeight AndAlso overExit = False AndAlso overMin = False Then formCanMove = True
  99. If overExit Then
  100. FindForm.Close()
  101. ElseIf overMin Then
  102. FindForm.WindowState = FormWindowState.Minimized
  103. overExit = False
  104. overMin = False
  105. Else
  106. Focus()
  107. End If
  108. Invalidate()
  109. End Sub
  110. Protected Overrides Sub OnMouseUp(ByVal e As System.Windows.Forms.MouseEventArgs)
  111. MyBase.OnMouseUp(e)
  112. formCanMove = False
  113. End Sub
  114. End Class
  115. Class ascButton
  116. Inherits Control
  117. Private _glowColor As Color
  118. Public Property GlowColor As Color
  119. Get
  120. Return _glowColor
  121. End Get
  122. Set(ByVal value As Color)
  123. _glowColor = value
  124. Invalidate()
  125. End Set
  126. End Property
  127. Enum State
  128. None
  129. Over
  130. Down
  131. End Enum
  132. Private MouseState As State
  133. Sub New()
  134. SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.OptimizedDoubleBuffer Or _
  135. ControlStyles.UserPaint Or ControlStyles.ResizeRedraw, True)
  136. Size = New Size(100, 40)
  137. Font = New Font("Arial", 11)
  138. Cursor = Cursors.Hand
  139. BackColor = Color.FromArgb(5, 30, 70)
  140. ForeColor = Color.FromArgb(195, 230, 255)
  141. GlowColor = Color.FromArgb(40, 95, 210)
  142. End Sub
  143. Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
  144. MyBase.OnPaint(e)
  145. Dim G As Graphics = e.Graphics
  146. G.SmoothingMode = SmoothingMode.HighQuality
  147. G.Clear(Parent.BackColor)
  148. Dim slope As Integer = 5
  149. Dim mainRect As New Rectangle(0, 0, Width - 1, Height - 1)
  150. Dim mainPath As GraphicsPath = RoundRect(mainRect, slope)
  151. G.FillPath(New LinearGradientBrush(mainRect, BackColor, Color.FromArgb(25, Color.Black), 90.0F), mainPath)
  152. G.DrawPath(New Pen(Color.FromArgb(BackColor.R / 2, BackColor.G / 2, BackColor.B / 2)), mainPath)
  153. Dim glow As Integer
  154. If MouseState = State.Over Then
  155. glow = 200
  156. ElseIf MouseState = State.Down Then
  157. glow = 255
  158. Else
  159. glow = 100
  160. End If
  161. G.DrawPath(New Pen(Color.FromArgb(glow, _glowColor)), mainPath)
  162. Dim textX As Integer = ((Width - 1) / 2) - (G.MeasureString(Text, Font).Width / 2)
  163. Dim textY As Integer = ((Height - 1) / 2) - (G.MeasureString(Text, Font).Height / 2)
  164. G.DrawString(Text, Font, New SolidBrush(ForeColor), New Point(textX, textY))
  165. End Sub
  166. Protected Overrides Sub OnMouseEnter(ByVal e As System.EventArgs)
  167. MyBase.OnMouseEnter(e)
  168. MouseState = State.Over
  169. Invalidate()
  170. End Sub
  171. Protected Overrides Sub OnMouseLeave(ByVal e As System.EventArgs)
  172. MyBase.OnMouseLeave(e)
  173. MouseState = State.None
  174. Invalidate()
  175. End Sub
  176. Protected Overrides Sub OnMouseUp(ByVal e As System.Windows.Forms.MouseEventArgs)
  177. MyBase.OnMouseUp(e)
  178. MouseState = State.Over
  179. Invalidate()
  180. End Sub
  181. Protected Overrides Sub OnMouseDown(ByVal e As System.Windows.Forms.MouseEventArgs)
  182. MyBase.OnMouseDown(e)
  183. MouseState = State.Down
  184. Invalidate()
  185. End Sub
  186. End Class
  187. Class ascButton_Big
  188. Inherits Control
  189. Private _glowColor As Color
  190. Public Property GlowColor As Color
  191. Get
  192. Return _glowColor
  193. End Get
  194. Set(ByVal value As Color)
  195. _glowColor = value
  196. Invalidate()
  197. End Set
  198. End Property
  199. Private _image As Image
  200. Public Property Image As Image
  201. Get
  202. Return _image
  203. End Get
  204. Set(ByVal value As Image)
  205. _image = value
  206. Invalidate()
  207. End Set
  208. End Property
  209. Enum State
  210. None
  211. Over
  212. Down
  213. End Enum
  214. Private MouseState As State
  215. Sub New()
  216. SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.OptimizedDoubleBuffer Or _
  217. ControlStyles.UserPaint Or ControlStyles.ResizeRedraw, True)
  218. Size = New Size(160, 60)
  219. Font = New Font("Arial", 11)
  220. Cursor = Cursors.Hand
  221. ForeColor = Color.FromArgb(5, 125, 250)
  222. GlowColor = Color.FromArgb(60, 150, 250)
  223. End Sub
  224. Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
  225. MyBase.OnPaint(e)
  226. Dim G As Graphics = e.Graphics
  227. G.SmoothingMode = SmoothingMode.HighQuality
  228. G.Clear(Parent.BackColor)
  229. Dim mainRect As New Rectangle(0, 0, Width - 1, Height - 1)
  230. G.FillRectangle(Brushes.Black, mainRect)
  231. G.DrawRectangle(New Pen(Color.FromArgb(30, 45, 60)), mainRect)
  232. Dim hCB As New ColorBlend(4)
  233. hCB.Colors(0) = Color.FromArgb(30, 45, 60)
  234. hCB.Colors(1) = _glowColor
  235. hCB.Colors(2) = _glowColor
  236. hCB.Colors(3) = hCB.Colors(0)
  237. hCB.Positions = New Single() {0.0, 0.35, 0.65, 1.0}
  238. Dim borderBrush As New LinearGradientBrush(mainRect, Color.Black, Color.Black, 0.0F)
  239. borderBrush.InterpolationColors = hCB
  240. G.DrawLine(New Pen(borderBrush), New Point(0, 0), New Point(Width - 1, 0))
  241. G.DrawLine(New Pen(borderBrush), New Point(0, Height - 1), New Point(Width - 1, Height - 1))
  242. Dim glow As Integer
  243. If MouseState = State.Over Then
  244. glow = 20
  245. ElseIf MouseState = State.Down Then
  246. glow = 30
  247. Else
  248. glow = 0
  249. End If
  250. G.FillRectangle(New SolidBrush(Color.FromArgb(glow, Color.WhiteSmoke)), mainRect)
  251. G.DrawRectangle(New Pen(Color.FromArgb(glow, _glowColor)), mainRect)
  252. Dim textX As Integer
  253. Dim textY As Integer = ((Height - 1) / 2) - (G.MeasureString(Text, Font).Height / 2)
  254. If Image IsNot Nothing Then
  255. Dim imageWidth As Integer = Me.Height - 24, imageHeight As Integer = Me.Height - 24
  256. Dim imageX As Integer = ((Me.Width - 1) / 2) - ((imageWidth + 4 + G.MeasureString(Text, Font).Width) / 2)
  257. Dim imageY As Integer = ((Me.Height - 1) / 2) - (imageHeight / 2)
  258. G.DrawImage(_image, imageX, imageY, imageWidth, imageHeight)
  259. textX = imageX + imageWidth + 4
  260. Else
  261. textX = ((Width - 1) / 2) - (G.MeasureString(Text, Font).Width / 2)
  262. End If
  263. G.DrawString(Text, Font, New SolidBrush(ForeColor), New Point(textX, textY))
  264. End Sub
  265. Protected Overrides Sub OnMouseEnter(ByVal e As System.EventArgs)
  266. MyBase.OnMouseEnter(e)
  267. MouseState = State.Over
  268. Invalidate()
  269. End Sub
  270. Protected Overrides Sub OnMouseLeave(ByVal e As System.EventArgs)
  271. MyBase.OnMouseLeave(e)
  272. MouseState = State.None
  273. Invalidate()
  274. End Sub
  275. Protected Overrides Sub OnMouseUp(ByVal e As System.Windows.Forms.MouseEventArgs)
  276. MyBase.OnMouseUp(e)
  277. MouseState = State.Over
  278. Invalidate()
  279. End Sub
  280. Protected Overrides Sub OnMouseDown(ByVal e As System.Windows.Forms.MouseEventArgs)
  281. MyBase.OnMouseDown(e)
  282. MouseState = State.Down
  283. Invalidate()
  284. End Sub
  285. End Class
  286. Class ascTabControl
  287. Inherits TabControl
  288. Sub New()
  289. SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.ResizeRedraw Or _
  290. ControlStyles.UserPaint Or ControlStyles.DoubleBuffer, True)
  291. ItemSize = New Size(0, 34)
  292. Padding = New Size(24, 0)
  293. Font = New Font("Arial", 12)
  294. End Sub
  295. Protected Overrides Sub CreateHandle()
  296. MyBase.CreateHandle()
  297. Alignment = TabAlignment.Top
  298. End Sub
  299. Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
  300. MyBase.OnPaint(e)
  301. Dim G As Graphics = e.Graphics
  302. G.SmoothingMode = SmoothingMode.HighQuality
  303. G.Clear(Parent.BackColor)
  304. Dim FontColor As New Color
  305. For i = 0 To TabCount - 1
  306. Dim mainRect As Rectangle = GetTabRect(i)
  307. If i = SelectedIndex Then
  308. FontColor = Color.FromArgb(80, 170, 245)
  309. G.DrawLine(New Pen(Color.FromArgb(5, 135, 250)), New Point(mainRect.X - 2, mainRect.Height - 1), New Point(mainRect.X + mainRect.Width - 2, mainRect.Height - 1))
  310. G.DrawLine(New Pen(Color.FromArgb(25, 100, 140)), New Point(mainRect.X - 2, mainRect.Height), New Point(mainRect.X + mainRect.Width - 2, mainRect.Height))
  311. Else
  312. FontColor = Color.FromArgb(160, 160, 160)
  313. G.DrawLine(New Pen(Color.FromArgb(30, 55, 85)), New Point(mainRect.X - 2, mainRect.Height - 1), New Point(mainRect.X + mainRect.Width - 2, mainRect.Height - 1))
  314. G.DrawLine(New Pen(Color.FromArgb(30, 55, 85)), New Point(mainRect.X - 2, mainRect.Height), New Point(mainRect.X + mainRect.Width - 2, mainRect.Height))
  315. End If
  316. If i <> 0 Then
  317. G.DrawLine(New Pen(Color.FromArgb(30, 90, 125)), New Point(mainRect.X - 4, mainRect.Height - 7), New Point(mainRect.X + 4, mainRect.Y + 6))
  318. End If
  319. Dim titleX As Integer = (mainRect.Location.X + mainRect.Width / 2) - (G.MeasureString(TabPages(i).Text, Font).Width / 2)
  320. Dim titleY As Integer = (mainRect.Location.Y + mainRect.Height / 2) - (G.MeasureString(TabPages(i).Text, Font).Height / 2)
  321. G.DrawString(TabPages(i).Text, Font, New SolidBrush(FontColor), New Point(titleX, titleY))
  322. Try : TabPages(i).BackColor = Parent.BackColor : Catch : End Try
  323. Next
  324. End Sub
  325. End Class
  326. Class ascProgressBar
  327. Inherits Control
  328. Private _Maximum As Integer = 100
  329. Public Property Maximum As Integer
  330. Get
  331. Return _Maximum
  332. End Get
  333. Set(ByVal v As Integer)
  334. If v < 1 Then v = 1
  335. If v < _Value Then _Value = v
  336. _Maximum = v
  337. Invalidate()
  338. End Set
  339. End Property
  340. Private _Value As Integer
  341. Public Property Value As Integer
  342. Get
  343. Return _Value
  344. End Get
  345. Set(ByVal v As Integer)
  346. If v > _Maximum Then v = Maximum
  347. _Value = v
  348. Invalidate()
  349. End Set
  350. End Property
  351. Private _percent As Integer
  352. Public ReadOnly Property Percent As Integer
  353. Get
  354. Return _percent
  355. End Get
  356. End Property
  357. Sub New()
  358. SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.OptimizedDoubleBuffer Or _
  359. ControlStyles.UserPaint Or ControlStyles.ResizeRedraw, True)
  360. Size = New Size(200, 40)
  361. Font = New Font("Arial", 11)
  362. End Sub
  363. Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
  364. MyBase.OnPaint(e)
  365. Dim G As Graphics = e.Graphics
  366. G.SmoothingMode = SmoothingMode.HighQuality
  367. G.Clear(Parent.BackColor)
  368. Dim slope As Integer = 3
  369. _percent = (_Value / _Maximum) * 100
  370. Dim midY As Integer = ((Height - 1) / 2)
  371. Dim mainRect As New Rectangle(12, midY - 4, Width - 25, 7)
  372. Dim mainPath As GraphicsPath = RoundRect(mainRect, slope)
  373. Dim barBrush As New LinearGradientBrush(mainRect, Color.FromArgb(32, 32, 32), Color.FromArgb(45, 45, 45), 90.0F)
  374. G.FillPath(barBrush, mainPath)
  375. Dim barRect As New Rectangle(12, midY - 4, CInt(((Width / _Maximum) * _Value) - ((_percent - 1) / 4)), 7)
  376. If barRect.Width > 0 Then
  377. Dim barHorizontal As New LinearGradientBrush(barRect, Color.FromArgb(5, 80, 140), Color.FromArgb(45, 180, 200), 0.0F)
  378. G.FillPath(barHorizontal, RoundRect(barRect, slope))
  379. Dim vertCB As New ColorBlend(5)
  380. vertCB.Colors(0) = Color.Transparent
  381. vertCB.Colors(1) = Color.Transparent
  382. vertCB.Colors(2) = Color.FromArgb(0, 150, 220)
  383. vertCB.Colors(3) = Color.Transparent
  384. vertCB.Colors(4) = Color.Transparent
  385. vertCB.Positions = New Single() {0.0, 0.4, 0.5, 0.6, 1.0}
  386. Dim barVertical As New LinearGradientBrush(barRect, Color.Black, Color.Black, 90.0F)
  387. barVertical.InterpolationColors = vertCB
  388. G.FillPath(barVertical, RoundRect(barRect, slope))
  389. End If
  390. If _Value > 0 Then
  391. Dim bubbleRect As New Rectangle(barRect.Width - 3, 0, midY * 2 - 3, midY * 2)
  392. Dim bubblePath As GraphicsPath = RoundRect(bubbleRect, midY)
  393. Dim bubbleBrush As New PathGradientBrush(bubblePath)
  394. bubbleBrush.CenterColor = Color.FromArgb(230, 245, 255)
  395. bubbleBrush.SurroundColors = {Color.Transparent}
  396. G.FillPath(bubbleBrush, bubblePath)
  397. End If
  398. End Sub
  399. End Class
  400. <DefaultEvent("CheckedChanged")> Class ascCheckBox
  401. Inherits Control
  402. Event CheckedChanged(ByVal sender As Object)
  403. Private _checked As Boolean
  404. Public Property Checked() As Boolean
  405. Get
  406. Return _checked
  407. End Get
  408. Set(ByVal value As Boolean)
  409. _checked = value
  410. Invalidate()
  411. End Set
  412. End Property
  413. Sub New()
  414. SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.OptimizedDoubleBuffer Or _
  415. ControlStyles.UserPaint Or ControlStyles.ResizeRedraw, True)
  416. Size = New Size(120, 17)
  417. Font = New Font("Arial", 9)
  418. End Sub
  419. Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
  420. MyBase.OnPaint(e)
  421. Dim G As Graphics = e.Graphics
  422. G.SmoothingMode = SmoothingMode.HighQuality
  423. G.Clear(Parent.BackColor)
  424. Height = 17
  425. Dim boxRect As New Rectangle(1, 1, Height - 3, Height - 3)
  426. G.DrawEllipse(New Pen(Color.FromArgb(30, 140, 240), 2), boxRect)
  427. Dim textY As Integer = ((Height - 1) / 2) - (G.MeasureString(Text, Font).Height / 2)
  428. G.DrawString(Text, Font, New SolidBrush(Color.FromArgb(160, 160, 160)), New Point((Height - 1) + 4, textY))
  429. If _checked Then G.DrawString("a", New Font("Marlett", 17), New SolidBrush(Color.FromArgb(120, 180, 255)), New Point(-3, -5))
  430. End Sub
  431. Protected Overrides Sub OnMouseDown(ByVal e As System.Windows.Forms.MouseEventArgs)
  432. MyBase.OnMouseDown(e)
  433. If _checked Then
  434. _checked = False
  435. Else
  436. _checked = True
  437. End If
  438. RaiseEvent CheckedChanged(Me)
  439. Invalidate()
  440. End Sub
  441. End Class
  442. <DefaultEvent("CheckedChanged")> Class ascSwitch
  443. Inherits Control
  444. Event CheckedChanged(ByVal sender As Object)
  445. Private _checked As Boolean
  446. Public Property Checked() As Boolean
  447. Get
  448. Return _checked
  449. End Get
  450. Set(ByVal value As Boolean)
  451. _checked = value
  452. Invalidate()
  453. End Set
  454. End Property
  455. Sub New()
  456. SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.OptimizedDoubleBuffer Or _
  457. ControlStyles.UserPaint Or ControlStyles.ResizeRedraw, True)
  458. Size = New Size(40, 17)
  459. End Sub
  460. Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
  461. MyBase.OnPaint(e)
  462. Dim G As Graphics = e.Graphics
  463. G.SmoothingMode = SmoothingMode.HighQuality
  464. G.Clear(Parent.BackColor)
  465. Dim slope As Integer = (Height - 1) / 2
  466. Height = 17
  467. Dim mainRect As New Rectangle(0, 0, Width - 1, Height - 1)
  468. Dim mainPath As GraphicsPath = RoundRect(mainRect, slope)
  469. If _checked Then
  470. Dim bgBrush As New LinearGradientBrush(mainRect, Color.FromArgb(10, 30, 50), Color.FromArgb(5, 80, 140), 90.0F)
  471. G.FillPath(bgBrush, mainPath)
  472. Dim switchRect As New Rectangle(Width - 14, 3, 10, 10)
  473. Dim switchBrush As New LinearGradientBrush(switchRect, Color.FromArgb(100, 220, 250), Color.FromArgb(15, 150, 220), 90.0F)
  474. G.FillEllipse(switchBrush, switchRect)
  475. Dim textY As Integer = ((Height - 1) / 2) - (G.MeasureString("On", New Font("Arial", 8)).Height / 2) + 1
  476. G.DrawString("On", New Font("Arial", 8), New SolidBrush(Color.FromArgb(180, 180, 180)), New Point(5, textY))
  477. G.DrawPath(New Pen(Color.FromArgb(5, 80, 140)), mainPath)
  478. Else
  479. Dim bgBrush As New LinearGradientBrush(mainRect, Color.FromArgb(40, 40, 40), Color.FromArgb(80, 80, 80), 90.0F)
  480. G.FillPath(bgBrush, mainPath)
  481. Dim switchRect As New Rectangle(3, 3, 10, 10)
  482. Dim switchBrush As New LinearGradientBrush(switchRect, Color.FromArgb(150, 150, 150), Color.FromArgb(120, 120, 120), 90.0F)
  483. G.FillEllipse(switchBrush, switchRect)
  484. Dim textY As Integer = ((Height - 1) / 2) - (G.MeasureString("Off", New Font("Arial", 8)).Height / 2) + 1
  485. G.DrawString("Off", New Font("Arial", 8), New SolidBrush(Color.FromArgb(180, 180, 180)), New Point(15, textY))
  486. G.DrawPath(New Pen(Color.FromArgb(80, 80, 80)), mainPath)
  487. End If
  488. End Sub
  489. Protected Overrides Sub OnMouseDown(ByVal e As System.Windows.Forms.MouseEventArgs)
  490. MyBase.OnMouseDown(e)
  491. If _checked Then
  492. _checked = False
  493. Else
  494. _checked = True
  495. End If
  496. RaiseEvent CheckedChanged(Me)
  497. Invalidate()
  498. End Sub
  499. End Class

comments powered by Disqus