Guest User

Untitled

a guest
Aug 15th, 2013
121
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Imports System, System.IO, System.Collections.Generic
  2. Imports System.Drawing, System.Drawing.Drawing2D
  3. Imports System.ComponentModel, System.Windows.Forms
  4. Class WinEightTheme
  5. Inherits ThemeContainer151
  6. Private C1, C2, C3 As Color
  7. Private B1 As SolidBrush
  8. Private P1, P2 As Pen
  9. Sub New()
  10. MoveHeight = 20
  11. SetColor("BackColor", Color.White)
  12. TransparencyKey = Color.Fuchsia
  13. End Sub
  14. Protected Overrides Sub ColorHook()
  15. C1 = GetColor("BackColor")
  16. C2 = Color.FromArgb(0, 162, 255)
  17. C3 = Color.FromArgb(0, 162, 255)
  18. P1 = New Pen(Color.FromArgb(90, 90, 50))
  19. P2 = New Pen(Color.FromArgb(90, 90, 90))
  20. End Sub
  21. ' Security.Najaf@Dev-Point.com
  22. Protected Overrides Sub PaintHook()
  23. G.Clear(C1)
  24. DrawGradient(Color.FromArgb(15, 15, 15), Color.FromArgb(30, 30, 30), 0, 0, Width, Height, 90S)
  25. DrawGradient(C2, C3, 0, 0, Width, Height)
  26. G.DrawLine(P1, 0, 0, 0, 20)
  27. G.DrawLine(P1, Width - 1, 0, Width - 1, 25)
  28. G.DrawLine(P2, 0, 0, 0, Height)
  29. G.DrawLine(P2, Width - 1, 0, Width - 1, Height)
  30. G.DrawLine(P2, 0, Height - 1, Width, Height - 1)
  31. G.FillRectangle(New SolidBrush(Color.FromArgb(240, 240, 240)), 10, 20, Width - 20, Height - 30)
  32. G.DrawLine(P2, 0, 0, Width, 0)
  33. DrawText(Brushes.White, HorizontalAlignment.Center, 0, 0)
  34. End Sub
  35. End Class
  36.  
  37. Class WinEightButton
  38.  
  39. Inherits ThemeControl151
  40. Private C1, C2, C3 As Color
  41. Private P1 As Pen
  42. Sub New()
  43. SetColor("BackColor", Color.Black)
  44. End Sub
  45. Protected Overrides Sub ColorHook()
  46. C1 = GetColor("BackColor")
  47. C2 = Color.FromArgb(230, 230, 230)
  48. C3 = Color.FromArgb(239, 239, 239)
  49. P1 = New Pen(Color.FromArgb(172, 172, 172))
  50. End Sub
  51.  
  52. Protected Overrides Sub PaintHook()
  53. G.Clear(C1)
  54. If (State = MouseState.Over) Then
  55. DrawGradient(C2, C3, 0, 0, Width, Height)
  56. ElseIf (State = MouseState.Down) Then
  57. DrawGradient(C3, C2, 0, 0, Width, Height)
  58. Else
  59. DrawGradient(C3, C2, 0, 0, Width, Height)
  60. End If
  61. DrawBorders(P1, ClientRectangle)
  62. DrawText(Brushes.Black, HorizontalAlignment.Center, 0, 0)
  63. End Sub
  64. End Class
  65. Class WinEightCloseButton
  66.  
  67. Inherits ThemeControl151
  68. Private C1, C2, C3 As Color
  69. Sub New()
  70. SetColor("BackColor", Color.Black)
  71. End Sub
  72. Protected Overrides Sub ColorHook()
  73. C1 = GetColor("BackColor")
  74. C2 = Color.FromArgb(199, 80, 80)
  75. C3 = Color.FromArgb(199, 80, 80)
  76. End Sub
  77.  
  78. Protected Overrides Sub PaintHook()
  79. G.Clear(C1)
  80. If (State = MouseState.Over) Then
  81. DrawGradient(C2, C3, 0, 0, Width, Height)
  82. ElseIf (State = MouseState.Down) Then
  83. DrawGradient(C3, C2, 0, 0, Width, Height)
  84. Else
  85. DrawGradient(C3, C2, 0, 0, Width, Height)
  86. End If
  87. DrawText(Brushes.White, HorizontalAlignment.Center, 0, 0)
  88. End Sub
  89. End Class
  90. Class WinEightMinimizeButton
  91.  
  92. Inherits ThemeControl151
  93. Private C1, C2, C3 As Color
  94. Sub New()
  95. SetColor("BackColor", Color.Black)
  96. End Sub
  97. Protected Overrides Sub ColorHook()
  98. C1 = GetColor("BackColor")
  99. C2 = Color.FromArgb(80, 199, 84)
  100. C3 = Color.FromArgb(80, 199, 84)
  101. End Sub
  102.  
  103. Protected Overrides Sub PaintHook()
  104. G.Clear(C1)
  105. If (State = MouseState.Over) Then
  106. DrawGradient(C2, C3, 0, 0, Width, Height)
  107. ElseIf (State = MouseState.Down) Then
  108. DrawGradient(C3, C2, 0, 0, Width, Height)
  109. Else
  110. DrawGradient(C3, C2, 0, 0, Width, Height)
  111. End If
  112. DrawText(Brushes.White, HorizontalAlignment.Center, 0, 0)
  113. End Sub
  114. End Class
  115.  
  116. '------------------
  117. 'Creator: Revvv
  118. 'Created: 11/3/2013
  119. '------------------
  120.  
  121. Enum MouseState As Byte
  122. None = 0
  123. Over = 1
  124. Down = 2
  125. Block = 3
  126. End Enum
  127.  
  128. Class Bloom
  129.  
  130. Private _Name As String
  131. Property Name() As String
  132. Get
  133. Return _Name
  134. End Get
  135. Set(ByVal value As String)
  136. _Name = value
  137. End Set
  138. End Property
  139.  
  140. Private _Value As Color
  141. Property Value() As Color
  142. Get
  143. Return _Value
  144. End Get
  145. Set(ByVal value As Color)
  146. _Value = value
  147. End Set
  148. End Property
  149.  
  150. Sub New()
  151. End Sub
  152.  
  153. Sub New(ByVal name As String, ByVal value As Color)
  154. _Name = name
  155. _Value = value
  156. End Sub
  157. End Class
  158.  
  159. MustInherit Class ThemeContainer151
  160. Inherits ContainerControl
  161.  
  162. Protected G As Graphics
  163.  
  164. Sub New()
  165. SetStyle(DirectCast(139270, ControlStyles), True)
  166. _ImageSize = Size.Empty
  167.  
  168. MeasureBitmap = New Bitmap(1, 1)
  169. MeasureGraphics = Graphics.FromImage(MeasureBitmap)
  170.  
  171. Font = New Font("Verdana", 8S)
  172.  
  173. InvalidateCustimization()
  174. End Sub
  175.  
  176. Protected Overrides Sub SetBoundsCore(ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer, ByVal specified As BoundsSpecified)
  177. If Not _LockWidth = 0 Then width = _LockWidth
  178. If Not _LockHeight = 0 Then height = _LockHeight
  179. MyBase.SetBoundsCore(x, y, width, height, specified)
  180. End Sub
  181.  
  182. Private Header As Rectangle
  183. Protected NotOverridable Overrides Sub OnSizeChanged(ByVal e As EventArgs)
  184. MyBase.OnSizeChanged(e)
  185. If _Movable AndAlso Not _ControlMode Then Header = New Rectangle(7, 7, Width - 14, _MoveHeight - 7)
  186. Invalidate()
  187. End Sub
  188.  
  189. Protected NotOverridable Overrides Sub OnPaint(ByVal e As PaintEventArgs)
  190. If Width = 0 OrElse Height = 0 Then Return
  191. G = e.Graphics
  192. PaintHook()
  193. End Sub
  194.  
  195. Protected NotOverridable Overrides Sub OnHandleCreated(ByVal e As EventArgs)
  196. InitializeMessages()
  197. InvalidateCustimization()
  198. ColorHook()
  199.  
  200. _IsParentForm = TypeOf Parent Is Form
  201. If Not _ControlMode Then Dock = DockStyle.Fill
  202.  
  203. If Not _LockWidth = 0 Then Width = _LockWidth
  204. If Not _LockHeight = 0 Then Height = _LockHeight
  205. If Not BackColorWait = Nothing Then BackColor = BackColorWait
  206.  
  207. If _IsParentForm AndAlso Not _ControlMode Then
  208. ParentForm.FormBorderStyle = _BorderStyle
  209. ParentForm.TransparencyKey = _TransparencyKey
  210. End If
  211.  
  212. OnCreation()
  213. MyBase.OnHandleCreated(e)
  214. End Sub
  215.  
  216. Protected Overridable Sub OnCreation()
  217. End Sub
  218.  
  219. #Region " Sizing and Movement "
  220.  
  221. Protected State As MouseState
  222. Private Sub SetState(ByVal current As MouseState)
  223. State = current
  224. Invalidate()
  225. End Sub
  226.  
  227. Protected Overrides Sub OnMouseMove(ByVal e As MouseEventArgs)
  228. If _Sizable AndAlso Not _ControlMode Then InvalidateMouse()
  229. MyBase.OnMouseMove(e)
  230. End Sub
  231.  
  232. Protected Overrides Sub OnEnabledChanged(ByVal e As EventArgs)
  233. If Enabled Then SetState(MouseState.None) Else SetState(MouseState.Block)
  234. MyBase.OnEnabledChanged(e)
  235. End Sub
  236.  
  237. Protected Overrides Sub OnMouseEnter(ByVal e As EventArgs)
  238. SetState(MouseState.Over)
  239. MyBase.OnMouseEnter(e)
  240. End Sub
  241.  
  242. Protected Overrides Sub OnMouseUp(ByVal e As MouseEventArgs)
  243. SetState(MouseState.Over)
  244. MyBase.OnMouseUp(e)
  245. End Sub
  246.  
  247. Protected Overrides Sub OnMouseLeave(ByVal e As EventArgs)
  248. SetState(MouseState.None)
  249.  
  250. If _Sizable AndAlso Not _ControlMode AndAlso GetChildAtPoint(PointToClient(MousePosition)) IsNot Nothing Then
  251. Cursor = Cursors.Default
  252. Previous = 0
  253. End If
  254.  
  255. MyBase.OnMouseLeave(e)
  256. End Sub
  257.  
  258. Protected Overrides Sub OnMouseDown(ByVal e As MouseEventArgs)
  259. MyBase.OnMouseDown(e)
  260.  
  261. If Not e.Button = Windows.Forms.MouseButtons.Left Then Return
  262. SetState(MouseState.Down)
  263.  
  264. If _IsParentForm AndAlso ParentForm.WindowState = FormWindowState.Maximized OrElse _ControlMode Then Return
  265.  
  266. If _Movable AndAlso Header.Contains(e.Location) Then
  267. Capture = False
  268. DefWndProc(Messages(0))
  269. ElseIf _Sizable AndAlso Not Previous = 0 Then
  270. Capture = False
  271. DefWndProc(Messages(Previous))
  272. End If
  273. End Sub
  274.  
  275. Private GetIndexPoint As Point
  276. Private B1, B2, B3, B4 As Boolean
  277. Private Function GetIndex() As Integer
  278. GetIndexPoint = PointToClient(MousePosition)
  279. B1 = GetIndexPoint.X < 7
  280. B2 = GetIndexPoint.X > Width - 7
  281. B3 = GetIndexPoint.Y < 7
  282. B4 = GetIndexPoint.Y > Height - 7
  283.  
  284. If B1 AndAlso B3 Then Return 4
  285. If B1 AndAlso B4 Then Return 7
  286. If B2 AndAlso B3 Then Return 5
  287. If B2 AndAlso B4 Then Return 8
  288. If B1 Then Return 1
  289. If B2 Then Return 2
  290. If B3 Then Return 3
  291. If B4 Then Return 6
  292. Return 0
  293. End Function
  294.  
  295. Private Current, Previous As Integer
  296. Private Sub InvalidateMouse()
  297. Current = GetIndex()
  298. If Current = Previous Then Return
  299.  
  300. Previous = Current
  301. Select Case Previous
  302. Case 0
  303. Cursor = Cursors.Default
  304. Case 1, 2
  305. Cursor = Cursors.SizeWE
  306. Case 3, 6
  307. Cursor = Cursors.SizeNS
  308. Case 4, 8
  309. Cursor = Cursors.SizeNWSE
  310. Case 5, 7
  311. Cursor = Cursors.SizeNESW
  312. End Select
  313. End Sub
  314.  
  315. Private Messages(8) As Message
  316. Private Sub InitializeMessages()
  317. Messages(0) = Message.Create(Parent.Handle, 161, New IntPtr(2), IntPtr.Zero)
  318. For I As Integer = 1 To 8
  319. Messages(I) = Message.Create(Parent.Handle, 161, New IntPtr(I + 9), IntPtr.Zero)
  320. Next
  321. End Sub
  322.  
  323. #End Region
  324.  
  325.  
  326. #Region " Property Overrides "
  327.  
  328. Private BackColorWait As Color
  329. Overrides Property BackColor() As Color
  330. Get
  331. Return MyBase.BackColor
  332. End Get
  333. Set(ByVal value As Color)
  334. If IsHandleCreated Then
  335. If Not _ControlMode Then Parent.BackColor = value
  336. MyBase.BackColor = value
  337. Else
  338. BackColorWait = value
  339. End If
  340. End Set
  341. End Property
  342.  
  343. <Browsable(False), EditorBrowsable(EditorBrowsableState.Never), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _
  344. Overrides Property ForeColor() As Color
  345. Get
  346. Return Color.Empty
  347. End Get
  348. Set(ByVal value As Color)
  349. End Set
  350. End Property
  351. <Browsable(False), EditorBrowsable(EditorBrowsableState.Never), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _
  352. Overrides Property BackgroundImage() As Image
  353. Get
  354. Return Nothing
  355. End Get
  356. Set(ByVal value As Image)
  357. End Set
  358. End Property
  359. <Browsable(False), EditorBrowsable(EditorBrowsableState.Never), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _
  360. Overrides Property BackgroundImageLayout() As ImageLayout
  361. Get
  362. Return ImageLayout.None
  363. End Get
  364. Set(ByVal value As ImageLayout)
  365. End Set
  366. End Property
  367.  
  368. Overrides Property Text() As String
  369. Get
  370. Return MyBase.Text
  371. End Get
  372. Set(ByVal value As String)
  373. MyBase.Text = value
  374. Invalidate()
  375. End Set
  376. End Property
  377.  
  378. Overrides Property Font() As Font
  379. Get
  380. Return MyBase.Font
  381. End Get
  382. Set(ByVal value As Font)
  383. MyBase.Font = value
  384. Invalidate()
  385. End Set
  386. End Property
  387.  
  388. #End Region
  389.  
  390. #Region " Properties "
  391.  
  392. Private _Movable As Boolean = True
  393. Property Movable() As Boolean
  394. Get
  395. Return _Movable
  396. End Get
  397. Set(ByVal value As Boolean)
  398. _Movable = value
  399. End Set
  400. End Property
  401.  
  402. Private _Sizable As Boolean = True
  403. Property Sizable() As Boolean
  404. Get
  405. Return _Sizable
  406. End Get
  407. Set(ByVal value As Boolean)
  408. _Sizable = value
  409. End Set
  410. End Property
  411.  
  412. Private _MoveHeight As Integer = 24
  413. Protected Property MoveHeight() As Integer
  414. Get
  415. Return _MoveHeight
  416. End Get
  417. Set(ByVal v As Integer)
  418. If v < 8 Then Return
  419. Header = New Rectangle(7, 7, Width - 14, v - 7)
  420. _MoveHeight = v
  421. Invalidate()
  422. End Set
  423. End Property
  424.  
  425. Private _ControlMode As Boolean
  426. Protected Property ControlMode() As Boolean
  427. Get
  428. Return _ControlMode
  429. End Get
  430. Set(ByVal v As Boolean)
  431. _ControlMode = v
  432. End Set
  433. End Property
  434.  
  435. Private _TransparencyKey As Color
  436. Property TransparencyKey() As Color
  437. Get
  438. If _IsParentForm AndAlso Not _ControlMode Then Return ParentForm.TransparencyKey Else Return _TransparencyKey
  439. End Get
  440. Set(ByVal value As Color)
  441. If _IsParentForm AndAlso Not _ControlMode Then ParentForm.TransparencyKey = value
  442. _TransparencyKey = value
  443. End Set
  444. End Property
  445.  
  446. Private _BorderStyle As FormBorderStyle
  447. Property BorderStyle() As FormBorderStyle
  448. Get
  449. If _IsParentForm AndAlso Not _ControlMode Then Return ParentForm.FormBorderStyle Else Return _BorderStyle
  450. End Get
  451. Set(ByVal value As FormBorderStyle)
  452. If _IsParentForm AndAlso Not _ControlMode Then ParentForm.FormBorderStyle = value
  453. _BorderStyle = value
  454. End Set
  455. End Property
  456.  
  457. Private _NoRounding As Boolean
  458. Property NoRounding() As Boolean
  459. Get
  460. Return _NoRounding
  461. End Get
  462. Set(ByVal v As Boolean)
  463. _NoRounding = v
  464. Invalidate()
  465. End Set
  466. End Property
  467.  
  468. Private _Image As Image
  469. Property Image() As Image
  470. Get
  471. Return _Image
  472. End Get
  473. Set(ByVal value As Image)
  474. If value Is Nothing Then
  475. _ImageSize = Size.Empty
  476. Else
  477. _ImageSize = value.Size
  478. End If
  479.  
  480. _Image = value
  481. Invalidate()
  482. End Set
  483. End Property
  484.  
  485. Private _ImageSize As Size
  486. Protected ReadOnly Property ImageSize() As Size
  487. Get
  488. Return _ImageSize
  489. End Get
  490. End Property
  491.  
  492. Private _IsParentForm As Boolean
  493. Protected ReadOnly Property IsParentForm As Boolean
  494. Get
  495. Return _IsParentForm
  496. End Get
  497. End Property
  498.  
  499. Private _LockWidth As Integer
  500. Protected Property LockWidth() As Integer
  501. Get
  502. Return _LockWidth
  503. End Get
  504. Set(ByVal value As Integer)
  505. _LockWidth = value
  506. If Not LockWidth = 0 AndAlso IsHandleCreated Then Width = LockWidth
  507. End Set
  508. End Property
  509.  
  510. Private _LockHeight As Integer
  511. Protected Property LockHeight() As Integer
  512. Get
  513. Return _LockHeight
  514. End Get
  515. Set(ByVal value As Integer)
  516. _LockHeight = value
  517. If Not LockHeight = 0 AndAlso IsHandleCreated Then Height = LockHeight
  518. End Set
  519. End Property
  520.  
  521. Private Items As New Dictionary(Of String, Color)
  522. <DesignerSerializationVisibility(DesignerSerializationVisibility.Content)> _
  523. Property Colors() As Bloom()
  524. Get
  525. Dim T As New List(Of Bloom)
  526. Dim E As Dictionary(Of String, Color).Enumerator = Items.GetEnumerator
  527.  
  528. While E.MoveNext
  529. T.Add(New Bloom(E.Current.Key, E.Current.Value))
  530. End While
  531.  
  532. Return T.ToArray
  533. End Get
  534. Set(ByVal value As Bloom())
  535. For Each B As Bloom In value
  536. If Items.ContainsKey(B.Name) Then Items(B.Name) = B.Value
  537. Next
  538.  
  539. InvalidateCustimization()
  540. ColorHook()
  541. Invalidate()
  542. End Set
  543. End Property
  544.  
  545. Private _Customization As String
  546. Property Customization() As String
  547. Get
  548. Return _Customization
  549. End Get
  550. Set(ByVal value As String)
  551. If value = _Customization Then Return
  552.  
  553. Dim Data As Byte()
  554. Dim Items As Bloom() = Colors
  555.  
  556. Try
  557. Data = Convert.FromBase64String(value)
  558. For I As Integer = 0 To Items.Length - 1
  559. Items(I).Value = Color.FromArgb(BitConverter.ToInt32(Data, I * 4))
  560. Next
  561. Catch
  562. Return
  563. End Try
  564.  
  565. _Customization = value
  566.  
  567. Colors = Items
  568. ColorHook()
  569. Invalidate()
  570. End Set
  571. End Property
  572.  
  573. #End Region
  574.  
  575. #Region " Property Helpers "
  576.  
  577. Protected Function GetColor(ByVal name As String) As Color
  578. Return Items(name)
  579. End Function
  580.  
  581. Protected Sub SetColor(ByVal name As String, ByVal color As Color)
  582. If Items.ContainsKey(name) Then Items(name) = color Else Items.Add(name, color)
  583. End Sub
  584. Protected Sub SetColor(ByVal name As String, ByVal r As Byte, ByVal g As Byte, ByVal b As Byte)
  585. SetColor(name, Color.FromArgb(r, g, b))
  586. End Sub
  587. Protected Sub SetColor(ByVal name As String, ByVal a As Byte, ByVal r As Byte, ByVal g As Byte, ByVal b As Byte)
  588. SetColor(name, Color.FromArgb(a, r, g, b))
  589. End Sub
  590. Protected Sub SetColor(ByVal name As String, ByVal a As Byte, ByVal color As Color)
  591. SetColor(name, color.FromArgb(a, color))
  592. End Sub
  593.  
  594. Private Sub InvalidateCustimization()
  595. Dim M As New MemoryStream(Items.Count * 4)
  596.  
  597. For Each B As Bloom In Colors
  598. M.Write(BitConverter.GetBytes(B.Value.ToArgb), 0, 4)
  599. Next
  600.  
  601. M.Close()
  602. _Customization = Convert.ToBase64String(M.ToArray)
  603. End Sub
  604.  
  605. #End Region
  606.  
  607.  
  608. #Region " User Hooks "
  609.  
  610. Protected MustOverride Sub ColorHook()
  611. Protected MustOverride Sub PaintHook()
  612.  
  613. #End Region
  614.  
  615.  
  616. #Region " Center Overloads "
  617.  
  618. Private CenterReturn As Point
  619.  
  620. Protected Function Center(ByVal r1 As Rectangle, ByVal s1 As Size) As Point
  621. CenterReturn = New Point((r1.Width \ 2 - s1.Width \ 2) + r1.X, (r1.Height \ 2 - s1.Height \ 2) + r1.Y)
  622. Return CenterReturn
  623. End Function
  624. Protected Function Center(ByVal r1 As Rectangle, ByVal r2 As Rectangle) As Point
  625. Return Center(r1, r2.Size)
  626. End Function
  627.  
  628. Protected Function Center(ByVal w1 As Integer, ByVal h1 As Integer, ByVal w2 As Integer, ByVal h2 As Integer) As Point
  629. CenterReturn = New Point(w1 \ 2 - w2 \ 2, h1 \ 2 - h2 \ 2)
  630. Return CenterReturn
  631. End Function
  632.  
  633. Protected Function Center(ByVal s1 As Size, ByVal s2 As Size) As Point
  634. Return Center(s1.Width, s1.Height, s2.Width, s2.Height)
  635. End Function
  636.  
  637. Protected Function Center(ByVal r1 As Rectangle) As Point
  638. Return Center(ClientRectangle.Width, ClientRectangle.Height, r1.Width, r1.Height)
  639. End Function
  640. Protected Function Center(ByVal s1 As Size) As Point
  641. Return Center(Width, Height, s1.Width, s1.Height)
  642. End Function
  643. Protected Function Center(ByVal w1 As Integer, ByVal h1 As Integer) As Point
  644. Return Center(Width, Height, w1, h1)
  645. End Function
  646.  
  647. #End Region
  648.  
  649. #Region " Measure Overloads "
  650.  
  651. Private MeasureBitmap As Bitmap
  652. Private MeasureGraphics As Graphics
  653.  
  654. Protected Function Measure(ByVal text As String) As Size
  655. Return MeasureGraphics.MeasureString(text, Font, Width).ToSize
  656. End Function
  657. Protected Function Measure() As Size
  658. Return MeasureGraphics.MeasureString(Text, Font).ToSize
  659. End Function
  660.  
  661. #End Region
  662.  
  663. #Region " DrawCorners Overloads "
  664.  
  665. 'TODO: Optimize by checking brush color
  666.  
  667. Private DrawCornersBrush As SolidBrush
  668.  
  669. Protected Sub DrawCorners(ByVal c1 As Color)
  670. DrawCorners(c1, 0, 0, Width, Height)
  671. End Sub
  672. Protected Sub DrawCorners(ByVal c1 As Color, ByVal r1 As Rectangle)
  673. DrawCorners(c1, r1.X, r1.Y, r1.Width, r1.Height)
  674. End Sub
  675. Protected Sub DrawCorners(ByVal c1 As Color, ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer)
  676. If _NoRounding Then Return
  677.  
  678. DrawCornersBrush = New SolidBrush(c1)
  679. G.FillRectangle(DrawCornersBrush, x, y, 1, 1)
  680. G.FillRectangle(DrawCornersBrush, x + (width - 1), y, 1, 1)
  681. G.FillRectangle(DrawCornersBrush, x, y + (height - 1), 1, 1)
  682. G.FillRectangle(DrawCornersBrush, x + (width - 1), y + (height - 1), 1, 1)
  683. End Sub
  684.  
  685. #End Region
  686.  
  687. #Region " DrawBorders Overloads "
  688.  
  689. 'TODO: Remove triple overload?
  690.  
  691. Protected Sub DrawBorders(ByVal p1 As Pen, ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer, ByVal offset As Integer)
  692. DrawBorders(p1, x + offset, y + offset, width - (offset * 2), height - (offset * 2))
  693. End Sub
  694. Protected Sub DrawBorders(ByVal p1 As Pen, ByVal offset As Integer)
  695. DrawBorders(p1, 0, 0, Width, Height, offset)
  696. End Sub
  697. Protected Sub DrawBorders(ByVal p1 As Pen, ByVal r As Rectangle, ByVal offset As Integer)
  698. DrawBorders(p1, r.X, r.Y, r.Width, r.Height, offset)
  699. End Sub
  700.  
  701. Protected Sub DrawBorders(ByVal p1 As Pen, ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer)
  702. G.DrawRectangle(p1, x, y, width - 1, height - 1)
  703. End Sub
  704. Protected Sub DrawBorders(ByVal p1 As Pen)
  705. DrawBorders(p1, 0, 0, Width, Height)
  706. End Sub
  707. Protected Sub DrawBorders(ByVal p1 As Pen, ByVal r As Rectangle)
  708. DrawBorders(p1, r.X, r.Y, r.Width, r.Height)
  709. End Sub
  710.  
  711. #End Region
  712.  
  713. #Region " DrawText Overloads "
  714.  
  715. 'TODO: Remove triple overloads?
  716.  
  717. Private DrawTextPoint As Point
  718. Private DrawTextSize As Size
  719.  
  720. Protected Sub DrawText(ByVal b1 As Brush, ByVal a As HorizontalAlignment, ByVal x As Integer, ByVal y As Integer)
  721. DrawText(b1, Text, a, x, y)
  722. End Sub
  723. Protected Sub DrawText(ByVal b1 As Brush, ByVal p1 As Point)
  724. DrawText(b1, Text, p1.X, p1.Y)
  725. End Sub
  726. Protected Sub DrawText(ByVal b1 As Brush, ByVal x As Integer, ByVal y As Integer)
  727. DrawText(b1, Text, x, y)
  728. End Sub
  729.  
  730. Protected Sub DrawText(ByVal b1 As Brush, ByVal text As String, ByVal a As HorizontalAlignment, ByVal x As Integer, ByVal y As Integer)
  731. If text.Length = 0 Then Return
  732. DrawTextSize = Measure(text)
  733. DrawTextPoint = New Point(Width \ 2 - DrawTextSize.Width \ 2, MoveHeight \ 2 - DrawTextSize.Height \ 2)
  734.  
  735. Select Case a
  736. Case HorizontalAlignment.Left
  737. DrawText(b1, text, x, DrawTextPoint.Y + y)
  738. Case HorizontalAlignment.Center
  739. DrawText(b1, text, DrawTextPoint.X + x, DrawTextPoint.Y + y)
  740. Case HorizontalAlignment.Right
  741. DrawText(b1, text, Width - DrawTextSize.Width - x, DrawTextPoint.Y + y)
  742. End Select
  743. End Sub
  744. Protected Sub DrawText(ByVal b1 As Brush, ByVal text As String, ByVal p1 As Point)
  745. DrawText(b1, text, p1.X, p1.Y)
  746. End Sub
  747. Protected Sub DrawText(ByVal b1 As Brush, ByVal text As String, ByVal x As Integer, ByVal y As Integer)
  748. If text.Length = 0 Then Return
  749. G.DrawString(text, Font, b1, x, y)
  750. End Sub
  751.  
  752. #End Region
  753.  
  754. #Region " DrawImage Overloads "
  755.  
  756. 'TODO: Remove triple overloads?
  757.  
  758. Private DrawImagePoint As Point
  759.  
  760. Protected Sub DrawImage(ByVal a As HorizontalAlignment, ByVal x As Integer, ByVal y As Integer)
  761. DrawImage(_Image, a, x, y)
  762. End Sub
  763. Protected Sub DrawImage(ByVal p1 As Point)
  764. DrawImage(_Image, p1.X, p1.Y)
  765. End Sub
  766. Protected Sub DrawImage(ByVal x As Integer, ByVal y As Integer)
  767. DrawImage(_Image, x, y)
  768. End Sub
  769.  
  770. Protected Sub DrawImage(ByVal image As Image, ByVal a As HorizontalAlignment, ByVal x As Integer, ByVal y As Integer)
  771. If image Is Nothing Then Return
  772. DrawImagePoint = New Point(Width \ 2 - image.Width \ 2, MoveHeight \ 2 - image.Height \ 2)
  773.  
  774. Select Case a
  775. Case HorizontalAlignment.Left
  776. DrawImage(image, x, DrawImagePoint.Y + y)
  777. Case HorizontalAlignment.Center
  778. DrawImage(image, DrawImagePoint.X + x, DrawImagePoint.Y + y)
  779. Case HorizontalAlignment.Right
  780. DrawImage(image, Width - image.Width - x, DrawImagePoint.Y + y)
  781. End Select
  782. End Sub
  783. Protected Sub DrawImage(ByVal image As Image, ByVal p1 As Point)
  784. DrawImage(image, p1.X, p1.Y)
  785. End Sub
  786. Protected Sub DrawImage(ByVal image As Image, ByVal x As Integer, ByVal y As Integer)
  787. If image Is Nothing Then Return
  788. G.DrawImage(image, x, y, image.Width, image.Height)
  789. End Sub
  790.  
  791. #End Region
  792.  
  793. #Region " DrawGradient Overloads "
  794.  
  795. 'TODO: Remove triple overload?
  796.  
  797. Private DrawGradientBrush As LinearGradientBrush
  798. Private DrawGradientRectangle As Rectangle
  799.  
  800. Protected Sub DrawGradient(ByVal blend As ColorBlend, ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer)
  801. DrawGradient(blend, x, y, width, height, 90S)
  802. End Sub
  803. Protected Sub DrawGradient(ByVal c1 As Color, ByVal c2 As Color, ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer)
  804. DrawGradient(c1, c2, x, y, width, height, 90S)
  805. End Sub
  806.  
  807. Protected Sub DrawGradient(ByVal blend As ColorBlend, ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer, ByVal angle As Single)
  808. DrawGradientRectangle = New Rectangle(x, y, width, height)
  809. DrawGradient(blend, DrawGradientRectangle, angle)
  810. End Sub
  811. Protected Sub DrawGradient(ByVal c1 As Color, ByVal c2 As Color, ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer, ByVal angle As Single)
  812. DrawGradientRectangle = New Rectangle(x, y, width, height)
  813. DrawGradient(c1, c2, DrawGradientRectangle, angle)
  814. End Sub
  815.  
  816. Protected Sub DrawGradient(ByVal blend As ColorBlend, ByVal r As Rectangle, ByVal angle As Single)
  817. DrawGradientBrush = New LinearGradientBrush(r, Color.Empty, Color.Empty, angle)
  818. DrawGradientBrush.InterpolationColors = blend
  819. G.FillRectangle(DrawGradientBrush, r)
  820. End Sub
  821. Protected Sub DrawGradient(ByVal c1 As Color, ByVal c2 As Color, ByVal r As Rectangle, ByVal angle As Single)
  822. DrawGradientBrush = New LinearGradientBrush(r, c1, c2, angle)
  823. G.FillRectangle(DrawGradientBrush, r)
  824. End Sub
  825.  
  826. #End Region
  827.  
  828. End Class
  829.  
  830. MustInherit Class ThemeControl151
  831. Inherits Control
  832.  
  833. Protected G As Graphics, B As Bitmap
  834.  
  835. Sub New()
  836. SetStyle(DirectCast(139270, ControlStyles), True)
  837.  
  838. _ImageSize = Size.Empty
  839.  
  840. MeasureBitmap = New Bitmap(1, 1)
  841. MeasureGraphics = Graphics.FromImage(MeasureBitmap)
  842.  
  843. Font = New Font("Verdana", 8S)
  844.  
  845. InvalidateCustimization()
  846. End Sub
  847.  
  848. Protected Overrides Sub SetBoundsCore(ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer, ByVal specified As BoundsSpecified)
  849. If Not _LockWidth = 0 Then width = _LockWidth
  850. If Not _LockHeight = 0 Then height = _LockHeight
  851. MyBase.SetBoundsCore(x, y, width, height, specified)
  852. End Sub
  853.  
  854. Protected NotOverridable Overrides Sub OnSizeChanged(ByVal e As EventArgs)
  855. If _Transparent AndAlso Not (Width = 0 OrElse Height = 0) Then
  856. B = New Bitmap(Width, Height)
  857. G = Graphics.FromImage(B)
  858. End If
  859.  
  860. Invalidate()
  861. MyBase.OnSizeChanged(e)
  862. End Sub
  863.  
  864. Protected NotOverridable Overrides Sub OnPaint(ByVal e As PaintEventArgs)
  865. If Width = 0 OrElse Height = 0 Then Return
  866.  
  867. If _Transparent Then
  868. PaintHook()
  869. e.Graphics.DrawImage(B, 0, 0)
  870. Else
  871. G = e.Graphics
  872. PaintHook()
  873. End If
  874. End Sub
  875.  
  876. Protected Overrides Sub OnHandleCreated(ByVal e As EventArgs)
  877. InvalidateCustimization()
  878. ColorHook()
  879.  
  880. If Not _LockWidth = 0 Then Width = _LockWidth
  881. If Not _LockHeight = 0 Then Height = _LockHeight
  882. If Not BackColorWait = Nothing Then BackColor = BackColorWait
  883.  
  884. OnCreation()
  885. MyBase.OnHandleCreated(e)
  886. End Sub
  887.  
  888. Protected Overridable Sub OnCreation()
  889. End Sub
  890.  
  891. #Region " State Handling "
  892.  
  893. Protected Overrides Sub OnMouseEnter(ByVal e As EventArgs)
  894. SetState(MouseState.Over)
  895. MyBase.OnMouseEnter(e)
  896. End Sub
  897.  
  898. Protected Overrides Sub OnMouseUp(ByVal e As MouseEventArgs)
  899. SetState(MouseState.Over)
  900. MyBase.OnMouseUp(e)
  901. End Sub
  902.  
  903. Protected Overrides Sub OnMouseDown(ByVal e As MouseEventArgs)
  904. If e.Button = Windows.Forms.MouseButtons.Left Then SetState(MouseState.Down)
  905. MyBase.OnMouseDown(e)
  906. End Sub
  907.  
  908. Protected Overrides Sub OnMouseLeave(ByVal e As EventArgs)
  909. SetState(MouseState.None)
  910. MyBase.OnMouseLeave(e)
  911. End Sub
  912.  
  913. Protected Overrides Sub OnEnabledChanged(ByVal e As EventArgs)
  914. If Enabled Then SetState(MouseState.None) Else SetState(MouseState.Block)
  915. MyBase.OnEnabledChanged(e)
  916. End Sub
  917.  
  918. Protected State As MouseState
  919. Private Sub SetState(ByVal current As MouseState)
  920. State = current
  921. Invalidate()
  922. End Sub
  923.  
  924. #End Region
  925.  
  926.  
  927. #Region " Property Overrides "
  928.  
  929. Private BackColorWait As Color
  930. Overrides Property BackColor() As Color
  931. Get
  932. Return MyBase.BackColor
  933. End Get
  934. Set(ByVal value As Color)
  935. If IsHandleCreated Then
  936. MyBase.BackColor = value
  937. Else
  938. BackColorWait = value
  939. End If
  940. End Set
  941. End Property
  942.  
  943. <Browsable(False), EditorBrowsable(EditorBrowsableState.Never), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _
  944. Overrides Property ForeColor() As Color
  945. Get
  946. Return Color.Empty
  947. End Get
  948. Set(ByVal value As Color)
  949. End Set
  950. End Property
  951. <Browsable(False), EditorBrowsable(EditorBrowsableState.Never), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _
  952. Overrides Property BackgroundImage() As Image
  953. Get
  954. Return Nothing
  955. End Get
  956. Set(ByVal value As Image)
  957. End Set
  958. End Property
  959. <Browsable(False), EditorBrowsable(EditorBrowsableState.Never), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _
  960. Overrides Property BackgroundImageLayout() As ImageLayout
  961. Get
  962. Return ImageLayout.None
  963. End Get
  964. Set(ByVal value As ImageLayout)
  965. End Set
  966. End Property
  967.  
  968. Overrides Property Text() As String
  969. Get
  970. Return MyBase.Text
  971. End Get
  972. Set(ByVal value As String)
  973. MyBase.Text = value
  974. Invalidate()
  975. End Set
  976. End Property
  977.  
  978. Overrides Property Font() As Font
  979. Get
  980. Return MyBase.Font
  981. End Get
  982. Set(ByVal value As Font)
  983. MyBase.Font = value
  984. Invalidate()
  985. End Set
  986. End Property
  987.  
  988. #End Region
  989.  
  990. #Region " Properties "
  991.  
  992. Private _NoRounding As Boolean
  993. Property NoRounding() As Boolean
  994. Get
  995. Return _NoRounding
  996. End Get
  997. Set(ByVal v As Boolean)
  998. _NoRounding = v
  999. Invalidate()
  1000. End Set
  1001. End Property
  1002.  
  1003. Private _Image As Image
  1004. Property Image() As Image
  1005. Get
  1006. Return _Image
  1007. End Get
  1008. Set(ByVal value As Image)
  1009. If value Is Nothing Then
  1010. _ImageSize = Size.Empty
  1011. Else
  1012. _ImageSize = value.Size
  1013. End If
  1014.  
  1015. _Image = value
  1016. Invalidate()
  1017. End Set
  1018. End Property
  1019.  
  1020. Private _ImageSize As Size
  1021. Protected ReadOnly Property ImageSize() As Size
  1022. Get
  1023. Return _ImageSize
  1024. End Get
  1025. End Property
  1026.  
  1027. Private _LockWidth As Integer
  1028. Protected Property LockWidth() As Integer
  1029. Get
  1030. Return _LockWidth
  1031. End Get
  1032. Set(ByVal value As Integer)
  1033. _LockWidth = value
  1034. If Not LockWidth = 0 AndAlso IsHandleCreated Then Width = LockWidth
  1035. End Set
  1036. End Property
  1037.  
  1038. Private _LockHeight As Integer
  1039. Protected Property LockHeight() As Integer
  1040. Get
  1041. Return _LockHeight
  1042. End Get
  1043. Set(ByVal value As Integer)
  1044. _LockHeight = value
  1045. If Not LockHeight = 0 AndAlso IsHandleCreated Then Height = LockHeight
  1046. End Set
  1047. End Property
  1048.  
  1049. Private _Transparent As Boolean
  1050. Property Transparent() As Boolean
  1051. Get
  1052. Return _Transparent
  1053. End Get
  1054. Set(ByVal value As Boolean)
  1055. If Not value AndAlso Not BackColor.A = 255 Then
  1056. Throw New Exception("Unable to change value to false while a transparent BackColor is in use.")
  1057. End If
  1058.  
  1059. SetStyle(ControlStyles.Opaque, Not value)
  1060. SetStyle(ControlStyles.SupportsTransparentBackColor, value)
  1061.  
  1062. If value Then InvalidateBitmap() Else B = Nothing
  1063.  
  1064. _Transparent = value
  1065. Invalidate()
  1066. End Set
  1067. End Property
  1068.  
  1069. Private Items As New Dictionary(Of String, Color)
  1070. <DesignerSerializationVisibility(DesignerSerializationVisibility.Content)> _
  1071. Property Colors() As Bloom()
  1072. Get
  1073. Dim T As New List(Of Bloom)
  1074. Dim E As Dictionary(Of String, Color).Enumerator = Items.GetEnumerator
  1075.  
  1076. While E.MoveNext
  1077. T.Add(New Bloom(E.Current.Key, E.Current.Value))
  1078. End While
  1079.  
  1080. Return T.ToArray
  1081. End Get
  1082. Set(ByVal value As Bloom())
  1083. For Each B As Bloom In value
  1084. If Items.ContainsKey(B.Name) Then Items(B.Name) = B.Value
  1085. Next
  1086.  
  1087. InvalidateCustimization()
  1088. ColorHook()
  1089. Invalidate()
  1090. End Set
  1091. End Property
  1092.  
  1093. Private _Customization As String
  1094. Property Customization() As String
  1095. Get
  1096. Return _Customization
  1097. End Get
  1098. Set(ByVal value As String)
  1099. If value = _Customization Then Return
  1100.  
  1101. Dim Data As Byte()
  1102. Dim Items As Bloom() = Colors
  1103.  
  1104. Try
  1105. Data = Convert.FromBase64String(value)
  1106. For I As Integer = 0 To Items.Length - 1
  1107. Items(I).Value = Color.FromArgb(BitConverter.ToInt32(Data, I * 4))
  1108. Next
  1109. Catch
  1110. Return
  1111. End Try
  1112.  
  1113. _Customization = value
  1114.  
  1115. Colors = Items
  1116. ColorHook()
  1117. Invalidate()
  1118. End Set
  1119. End Property
  1120.  
  1121. #End Region
  1122.  
  1123. #Region " Property Helpers "
  1124.  
  1125. Private Sub InvalidateBitmap()
  1126. If Width = 0 OrElse Height = 0 Then Return
  1127. B = New Bitmap(Width, Height)
  1128. G = Graphics.FromImage(B)
  1129. End Sub
  1130.  
  1131. Protected Function GetColor(ByVal name As String) As Color
  1132. Return Items(name)
  1133. End Function
  1134.  
  1135. Protected Sub SetColor(ByVal name As String, ByVal color As Color)
  1136. If Items.ContainsKey(name) Then Items(name) = color Else Items.Add(name, color)
  1137. End Sub
  1138. Protected Sub SetColor(ByVal name As String, ByVal r As Byte, ByVal g As Byte, ByVal b As Byte)
  1139. SetColor(name, Color.FromArgb(r, g, b))
  1140. End Sub
  1141. Protected Sub SetColor(ByVal name As String, ByVal a As Byte, ByVal r As Byte, ByVal g As Byte, ByVal b As Byte)
  1142. SetColor(name, Color.FromArgb(a, r, g, b))
  1143. End Sub
  1144. Protected Sub SetColor(ByVal name As String, ByVal a As Byte, ByVal color As Color)
  1145. SetColor(name, color.FromArgb(a, color))
  1146. End Sub
  1147.  
  1148. Private Sub InvalidateCustimization()
  1149. Dim M As New MemoryStream(Items.Count * 4)
  1150.  
  1151. For Each B As Bloom In Colors
  1152. M.Write(BitConverter.GetBytes(B.Value.ToArgb), 0, 4)
  1153. Next
  1154.  
  1155. M.Close()
  1156. _Customization = Convert.ToBase64String(M.ToArray)
  1157. End Sub
  1158.  
  1159. #End Region
  1160.  
  1161.  
  1162. #Region " User Hooks "
  1163.  
  1164. Protected MustOverride Sub ColorHook()
  1165. Protected MustOverride Sub PaintHook()
  1166.  
  1167. #End Region
  1168.  
  1169.  
  1170. #Region " Center Overloads "
  1171.  
  1172. Private CenterReturn As Point
  1173.  
  1174. Protected Function Center(ByVal r1 As Rectangle, ByVal s1 As Size) As Point
  1175. CenterReturn = New Point((r1.Width \ 2 - s1.Width \ 2) + r1.X, (r1.Height \ 2 - s1.Height \ 2) + r1.Y)
  1176. Return CenterReturn
  1177. End Function
  1178. Protected Function Center(ByVal r1 As Rectangle, ByVal r2 As Rectangle) As Point
  1179. Return Center(r1, r2.Size)
  1180. End Function
  1181.  
  1182. Protected Function Center(ByVal w1 As Integer, ByVal h1 As Integer, ByVal w2 As Integer, ByVal h2 As Integer) As Point
  1183. CenterReturn = New Point(w1 \ 2 - w2 \ 2, h1 \ 2 - h2 \ 2)
  1184. Return CenterReturn
  1185. End Function
  1186.  
  1187. Protected Function Center(ByVal s1 As Size, ByVal s2 As Size) As Point
  1188. Return Center(s1.Width, s1.Height, s2.Width, s2.Height)
  1189. End Function
  1190.  
  1191. Protected Function Center(ByVal r1 As Rectangle) As Point
  1192. Return Center(ClientRectangle.Width, ClientRectangle.Height, r1.Width, r1.Height)
  1193. End Function
  1194. Protected Function Center(ByVal s1 As Size) As Point
  1195. Return Center(Width, Height, s1.Width, s1.Height)
  1196. End Function
  1197. Protected Function Center(ByVal w1 As Integer, ByVal h1 As Integer) As Point
  1198. Return Center(Width, Height, w1, h1)
  1199. End Function
  1200.  
  1201. #End Region
  1202.  
  1203. #Region " Measure Overloads "
  1204.  
  1205. Private MeasureBitmap As Bitmap
  1206. Private MeasureGraphics As Graphics
  1207.  
  1208. Protected Function Measure(ByVal text As String) As Size
  1209. Return MeasureGraphics.MeasureString(text, Font, Width).ToSize
  1210. End Function
  1211. Protected Function Measure() As Size
  1212. Return MeasureGraphics.MeasureString(Text, Font, Width).ToSize
  1213. End Function
  1214.  
  1215. #End Region
  1216.  
  1217. #Region " DrawCorners Overloads "
  1218.  
  1219. 'TODO: Optimize by checking brush color
  1220.  
  1221. Private DrawCornersBrush As SolidBrush
  1222.  
  1223. Protected Sub DrawCorners(ByVal c1 As Color)
  1224. DrawCorners(c1, 0, 0, Width, Height)
  1225. End Sub
  1226. Protected Sub DrawCorners(ByVal c1 As Color, ByVal r1 As Rectangle)
  1227. DrawCorners(c1, r1.X, r1.Y, r1.Width, r1.Height)
  1228. End Sub
  1229. Protected Sub DrawCorners(ByVal c1 As Color, ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer)
  1230. If _NoRounding Then Return
  1231.  
  1232. If _Transparent Then
  1233. B.SetPixel(x, y, c1)
  1234. B.SetPixel(x + (width - 1), y, c1)
  1235. B.SetPixel(x, y + (height - 1), c1)
  1236. B.SetPixel(x + (width - 1), y + (height - 1), c1)
  1237. Else
  1238. DrawCornersBrush = New SolidBrush(c1)
  1239. G.FillRectangle(DrawCornersBrush, x, y, 1, 1)
  1240. G.FillRectangle(DrawCornersBrush, x + (width - 1), y, 1, 1)
  1241. G.FillRectangle(DrawCornersBrush, x, y + (height - 1), 1, 1)
  1242. G.FillRectangle(DrawCornersBrush, x + (width - 1), y + (height - 1), 1, 1)
  1243. End If
  1244. End Sub
  1245.  
  1246. #End Region
  1247.  
  1248. #Region " DrawBorders Overloads "
  1249.  
  1250. 'TODO: Remove triple overload?
  1251.  
  1252. Protected Sub DrawBorders(ByVal p1 As Pen, ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer, ByVal offset As Integer)
  1253. DrawBorders(p1, x + offset, y + offset, width - (offset * 2), height - (offset * 2))
  1254. End Sub
  1255. Protected Sub DrawBorders(ByVal p1 As Pen, ByVal offset As Integer)
  1256. DrawBorders(p1, 0, 0, Width, Height, offset)
  1257. End Sub
  1258. Protected Sub DrawBorders(ByVal p1 As Pen, ByVal r As Rectangle, ByVal offset As Integer)
  1259. DrawBorders(p1, r.X, r.Y, r.Width, r.Height, offset)
  1260. End Sub
  1261.  
  1262. Protected Sub DrawBorders(ByVal p1 As Pen, ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer)
  1263. G.DrawRectangle(p1, x, y, width - 1, height - 1)
  1264. End Sub
  1265. Protected Sub DrawBorders(ByVal p1 As Pen)
  1266. DrawBorders(p1, 0, 0, Width, Height)
  1267. End Sub
  1268. Protected Sub DrawBorders(ByVal p1 As Pen, ByVal r As Rectangle)
  1269. DrawBorders(p1, r.X, r.Y, r.Width, r.Height)
  1270. End Sub
  1271.  
  1272. #End Region
  1273.  
  1274. #Region " DrawText Overloads "
  1275.  
  1276. 'TODO: Remove triple overloads?
  1277.  
  1278. Private DrawTextPoint As Point
  1279. Private DrawTextSize As Size
  1280.  
  1281. Protected Sub DrawText(ByVal b1 As Brush, ByVal a As HorizontalAlignment, ByVal x As Integer, ByVal y As Integer)
  1282. DrawText(b1, Text, a, x, y)
  1283. End Sub
  1284. Protected Sub DrawText(ByVal b1 As Brush, ByVal p1 As Point)
  1285. DrawText(b1, Text, p1.X, p1.Y)
  1286. End Sub
  1287. Protected Sub DrawText(ByVal b1 As Brush, ByVal x As Integer, ByVal y As Integer)
  1288. DrawText(b1, Text, x, y)
  1289. End Sub
  1290.  
  1291. Protected Sub DrawText(ByVal b1 As Brush, ByVal text As String, ByVal a As HorizontalAlignment, ByVal x As Integer, ByVal y As Integer)
  1292. If text.Length = 0 Then Return
  1293. DrawTextSize = Measure(text)
  1294. DrawTextPoint = Center(DrawTextSize)
  1295.  
  1296. Select Case a
  1297. Case HorizontalAlignment.Left
  1298. DrawText(b1, text, x, DrawTextPoint.Y + y)
  1299. Case HorizontalAlignment.Center
  1300. DrawText(b1, text, DrawTextPoint.X + x, DrawTextPoint.Y + y)
  1301. Case HorizontalAlignment.Right
  1302. DrawText(b1, text, Width - DrawTextSize.Width - x, DrawTextPoint.Y + y)
  1303. End Select
  1304. End Sub
  1305. Protected Sub DrawText(ByVal b1 As Brush, ByVal text As String, ByVal p1 As Point)
  1306. DrawText(b1, text, p1.X, p1.Y)
  1307. End Sub
  1308. Protected Sub DrawText(ByVal b1 As Brush, ByVal text As String, ByVal x As Integer, ByVal y As Integer)
  1309. If text.Length = 0 Then Return
  1310. G.DrawString(text, Font, b1, x, y)
  1311. End Sub
  1312.  
  1313. #End Region
  1314.  
  1315. #Region " DrawImage Overloads "
  1316.  
  1317. 'TODO: Remove triple overloads?
  1318.  
  1319. Private DrawImagePoint As Point
  1320.  
  1321. Protected Sub DrawImage(ByVal a As HorizontalAlignment, ByVal x As Integer, ByVal y As Integer)
  1322. DrawImage(_Image, a, x, y)
  1323. End Sub
  1324. Protected Sub DrawImage(ByVal p1 As Point)
  1325. DrawImage(_Image, p1.X, p1.Y)
  1326. End Sub
  1327. Protected Sub DrawImage(ByVal x As Integer, ByVal y As Integer)
  1328. DrawImage(_Image, x, y)
  1329. End Sub
  1330.  
  1331. Protected Sub DrawImage(ByVal image As Image, ByVal a As HorizontalAlignment, ByVal x As Integer, ByVal y As Integer)
  1332. If image Is Nothing Then Return
  1333. DrawImagePoint = Center(image.Size)
  1334.  
  1335. Select Case a
  1336. Case HorizontalAlignment.Left
  1337. DrawImage(image, x, DrawImagePoint.Y + y)
  1338. Case HorizontalAlignment.Center
  1339. DrawImage(image, DrawImagePoint.X + x, DrawImagePoint.Y + y)
  1340. Case HorizontalAlignment.Right
  1341. DrawImage(image, Width - image.Width - x, DrawImagePoint.Y + y)
  1342. End Select
  1343. End Sub
  1344. Protected Sub DrawImage(ByVal image As Image, ByVal p1 As Point)
  1345. DrawImage(image, p1.X, p1.Y)
  1346. End Sub
  1347. Protected Sub DrawImage(ByVal image As Image, ByVal x As Integer, ByVal y As Integer)
  1348. If image Is Nothing Then Return
  1349. G.DrawImage(image, x, y, image.Width, image.Height)
  1350. End Sub
  1351.  
  1352. #End Region
  1353.  
  1354. #Region " DrawGradient Overloads "
  1355.  
  1356. 'TODO: Remove triple overload?
  1357.  
  1358. Private DrawGradientBrush As LinearGradientBrush
  1359. Private DrawGradientRectangle As Rectangle
  1360.  
  1361. Protected Sub DrawGradient(ByVal blend As ColorBlend, ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer)
  1362. DrawGradient(blend, x, y, width, height, 90S)
  1363. End Sub
  1364. Protected Sub DrawGradient(ByVal c1 As Color, ByVal c2 As Color, ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer)
  1365. DrawGradient(c1, c2, x, y, width, height, 90S)
  1366. End Sub
  1367.  
  1368. Protected Sub DrawGradient(ByVal blend As ColorBlend, ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer, ByVal angle As Single)
  1369. DrawGradientRectangle = New Rectangle(x, y, width, height)
  1370. DrawGradient(blend, DrawGradientRectangle, angle)
  1371. End Sub
  1372. Protected Sub DrawGradient(ByVal c1 As Color, ByVal c2 As Color, ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer, ByVal angle As Single)
  1373. DrawGradientRectangle = New Rectangle(x, y, width, height)
  1374. DrawGradient(c1, c2, DrawGradientRectangle, angle)
  1375. End Sub
  1376.  
  1377. Protected Sub DrawGradient(ByVal blend As ColorBlend, ByVal r As Rectangle, ByVal angle As Single)
  1378. DrawGradientBrush = New LinearGradientBrush(r, Color.Empty, Color.Empty, angle)
  1379. DrawGradientBrush.InterpolationColors = blend
  1380. G.FillRectangle(DrawGradientBrush, r)
  1381. End Sub
  1382. Protected Sub DrawGradient(ByVal c1 As Color, ByVal c2 As Color, ByVal r As Rectangle, ByVal angle As Single)
  1383. DrawGradientBrush = New LinearGradientBrush(r, c1, c2, angle)
  1384. G.FillRectangle(DrawGradientBrush, r)
  1385. End Sub
  1386.  
  1387. #End Region
  1388.  
  1389. End Class
RAW Paste Data