Guest User

Untitled

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