Guest User

Untitled

a guest
Nov 22nd, 2011
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 99.53 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. Imports System.Runtime.InteropServices
  5. Imports System.Drawing.Imaging
  6.  
  7. '------------------
  8. 'Creator: aeonhack
  9. 'Site: elitevs.net
  10. 'Created: 08/02/2011
  11. 'Changed: 10/9/2011
  12. 'Version: 1.5.3
  13. '------------------
  14.  
  15. MustInherit Class ThemeContainer153
  16. Inherits ContainerControl
  17.  
  18. #Region " Initialization "
  19.  
  20. Protected G As Graphics, B As Bitmap
  21.  
  22. Sub New()
  23. SetStyle(DirectCast(139270, ControlStyles), True)
  24.  
  25. _ImageSize = Size.Empty
  26. Font = New Font("Verdana", 8S)
  27.  
  28. MeasureBitmap = New Bitmap(1, 1)
  29. MeasureGraphics = Graphics.FromImage(MeasureBitmap)
  30.  
  31. DrawRadialPath = New GraphicsPath
  32.  
  33. InvalidateCustimization() 'Remove?
  34. End Sub
  35.  
  36. Protected NotOverridable Overrides Sub OnHandleCreated(ByVal e As EventArgs)
  37. InvalidateCustimization()
  38. ColorHook()
  39.  
  40. If Not _LockWidth = 0 Then Width = _LockWidth
  41. If Not _LockHeight = 0 Then Height = _LockHeight
  42. If Not _ControlMode Then MyBase.Dock = DockStyle.Fill
  43.  
  44. Transparent = _Transparent
  45. If _Transparent AndAlso _BackColor Then BackColor = Color.Transparent
  46.  
  47. MyBase.OnHandleCreated(e)
  48. End Sub
  49.  
  50. Protected NotOverridable Overrides Sub OnParentChanged(ByVal e As EventArgs)
  51. MyBase.OnParentChanged(e)
  52.  
  53. If Parent Is Nothing Then Return
  54. _IsParentForm = TypeOf Parent Is Form
  55.  
  56. If Not _ControlMode Then
  57. InitializeMessages()
  58.  
  59. If _IsParentForm Then
  60. ParentForm.FormBorderStyle = _BorderStyle
  61. ParentForm.TransparencyKey = _TransparencyKey
  62. End If
  63.  
  64. Parent.BackColor = BackColor
  65. End If
  66.  
  67. OnCreation()
  68. End Sub
  69.  
  70. #End Region
  71.  
  72.  
  73. Protected NotOverridable Overrides Sub OnPaint(ByVal e As PaintEventArgs)
  74. If Width = 0 OrElse Height = 0 Then Return
  75.  
  76. If _Transparent AndAlso _ControlMode Then
  77. PaintHook()
  78. e.Graphics.DrawImage(B, 0, 0)
  79. Else
  80. G = e.Graphics
  81. PaintHook()
  82. End If
  83. End Sub
  84.  
  85.  
  86. #Region " Size Handling "
  87.  
  88. Private Frame As Rectangle
  89. Protected NotOverridable Overrides Sub OnSizeChanged(ByVal e As EventArgs)
  90. If _Movable AndAlso Not _ControlMode Then
  91. Frame = New Rectangle(7, 7, Width - 14, _Header - 7)
  92. End If
  93.  
  94. InvalidateBitmap()
  95. Invalidate()
  96.  
  97. MyBase.OnSizeChanged(e)
  98. End Sub
  99.  
  100. Protected Overrides Sub SetBoundsCore(ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer, ByVal specified As BoundsSpecified)
  101. If Not _LockWidth = 0 Then width = _LockWidth
  102. If Not _LockHeight = 0 Then height = _LockHeight
  103. MyBase.SetBoundsCore(x, y, width, height, specified)
  104. End Sub
  105.  
  106. #End Region
  107.  
  108. #Region " State Handling "
  109.  
  110. Protected State As MouseState
  111. Private Sub SetState(ByVal current As MouseState)
  112. State = current
  113. Invalidate()
  114. End Sub
  115.  
  116. Protected Overrides Sub OnMouseMove(ByVal e As MouseEventArgs)
  117. If Not (_IsParentForm AndAlso ParentForm.WindowState = FormWindowState.Maximized) Then
  118. If _Sizable AndAlso Not _ControlMode Then InvalidateMouse()
  119. End If
  120.  
  121. MyBase.OnMouseMove(e)
  122. End Sub
  123.  
  124. Protected Overrides Sub OnEnabledChanged(ByVal e As EventArgs)
  125. If Enabled Then SetState(MouseState.None) Else SetState(MouseState.Block)
  126. MyBase.OnEnabledChanged(e)
  127. End Sub
  128.  
  129. Protected Overrides Sub OnMouseEnter(ByVal e As EventArgs)
  130. SetState(MouseState.Over)
  131. MyBase.OnMouseEnter(e)
  132. End Sub
  133.  
  134. Protected Overrides Sub OnMouseUp(ByVal e As MouseEventArgs)
  135. SetState(MouseState.Over)
  136. MyBase.OnMouseUp(e)
  137. End Sub
  138.  
  139. Protected Overrides Sub OnMouseLeave(ByVal e As EventArgs)
  140. SetState(MouseState.None)
  141.  
  142. If GetChildAtPoint(PointToClient(MousePosition)) IsNot Nothing Then
  143. If _Sizable AndAlso Not _ControlMode Then
  144. Cursor = Cursors.Default
  145. Previous = 0
  146. End If
  147. End If
  148.  
  149. MyBase.OnMouseLeave(e)
  150. End Sub
  151.  
  152. Protected Overrides Sub OnMouseDown(ByVal e As MouseEventArgs)
  153. If e.Button = Windows.Forms.MouseButtons.Left Then SetState(MouseState.Down)
  154.  
  155. If Not (_IsParentForm AndAlso ParentForm.WindowState = FormWindowState.Maximized OrElse _ControlMode) Then
  156. If _Movable AndAlso Frame.Contains(e.Location) Then
  157. Capture = False
  158. WM_LMBUTTONDOWN = True
  159. DefWndProc(Messages(0))
  160. ElseIf _Sizable AndAlso Not Previous = 0 Then
  161. Capture = False
  162. WM_LMBUTTONDOWN = True
  163. DefWndProc(Messages(Previous))
  164. End If
  165. End If
  166.  
  167. MyBase.OnMouseDown(e)
  168. End Sub
  169.  
  170. Private WM_LMBUTTONDOWN As Boolean
  171. Protected Overrides Sub WndProc(ByRef m As Message)
  172. MyBase.WndProc(m)
  173.  
  174. If WM_LMBUTTONDOWN AndAlso m.Msg = 513 Then
  175. WM_LMBUTTONDOWN = False
  176.  
  177. SetState(MouseState.Over)
  178. If Not _SmartBounds Then Return
  179.  
  180. If IsParentMdi Then
  181. CorrectBounds(New Rectangle(Point.Empty, Parent.Parent.Size))
  182. Else
  183. CorrectBounds(Screen.FromControl(Parent).WorkingArea)
  184. End If
  185. End If
  186. End Sub
  187.  
  188. Private GetIndexPoint As Point
  189. Private B1, B2, B3, B4 As Boolean
  190. Private Function GetIndex() As Integer
  191. GetIndexPoint = PointToClient(MousePosition)
  192. B1 = GetIndexPoint.X < 7
  193. B2 = GetIndexPoint.X > Width - 7
  194. B3 = GetIndexPoint.Y < 7
  195. B4 = GetIndexPoint.Y > Height - 7
  196.  
  197. If B1 AndAlso B3 Then Return 4
  198. If B1 AndAlso B4 Then Return 7
  199. If B2 AndAlso B3 Then Return 5
  200. If B2 AndAlso B4 Then Return 8
  201. If B1 Then Return 1
  202. If B2 Then Return 2
  203. If B3 Then Return 3
  204. If B4 Then Return 6
  205. Return 0
  206. End Function
  207.  
  208. Private Current, Previous As Integer
  209. Private Sub InvalidateMouse()
  210. Current = GetIndex()
  211. If Current = Previous Then Return
  212.  
  213. Previous = Current
  214. Select Case Previous
  215. Case 0
  216. Cursor = Cursors.Default
  217. Case 1, 2
  218. Cursor = Cursors.SizeWE
  219. Case 3, 6
  220. Cursor = Cursors.SizeNS
  221. Case 4, 8
  222. Cursor = Cursors.SizeNWSE
  223. Case 5, 7
  224. Cursor = Cursors.SizeNESW
  225. End Select
  226. End Sub
  227.  
  228. Private Messages(8) As Message
  229. Private Sub InitializeMessages()
  230. Messages(0) = Message.Create(Parent.Handle, 161, New IntPtr(2), IntPtr.Zero)
  231. For I As Integer = 1 To 8
  232. Messages(I) = Message.Create(Parent.Handle, 161, New IntPtr(I + 9), IntPtr.Zero)
  233. Next
  234. End Sub
  235.  
  236. Private Sub CorrectBounds(ByVal bounds As Rectangle)
  237. If Parent.Width > bounds.Width Then Parent.Width = bounds.Width
  238. If Parent.Height > bounds.Height Then Parent.Height = bounds.Height
  239.  
  240. Dim X As Integer = Parent.Location.X
  241. Dim Y As Integer = Parent.Location.Y
  242.  
  243. If X < bounds.X Then X = bounds.X
  244. If Y < bounds.Y Then Y = bounds.Y
  245.  
  246. Dim Width As Integer = bounds.X + bounds.Width
  247. Dim Height As Integer = bounds.Y + bounds.Height
  248.  
  249. If X + Parent.Width > Width Then X = Width - Parent.Width
  250. If Y + Parent.Height > Height Then Y = Height - Parent.Height
  251.  
  252. Parent.Location = New Point(X, Y)
  253. End Sub
  254.  
  255. #End Region
  256.  
  257.  
  258. #Region " Base Properties "
  259.  
  260. Overrides Property Dock As DockStyle
  261. Get
  262. Return MyBase.Dock
  263. End Get
  264. Set(ByVal value As DockStyle)
  265. If Not _ControlMode Then Return
  266. MyBase.Dock = value
  267. End Set
  268. End Property
  269.  
  270. Private _BackColor As Boolean
  271. <Category("Misc")> _
  272. Overrides Property BackColor() As Color
  273. Get
  274. Return MyBase.BackColor
  275. End Get
  276. Set(ByVal value As Color)
  277. If value = MyBase.BackColor Then Return
  278.  
  279. If Not IsHandleCreated AndAlso _ControlMode AndAlso value = Color.Transparent Then
  280. _BackColor = True
  281. Return
  282. End If
  283.  
  284. MyBase.BackColor = value
  285. If Parent IsNot Nothing Then
  286. If Not _ControlMode Then Parent.BackColor = value
  287. ColorHook()
  288. End If
  289. End Set
  290. End Property
  291.  
  292. Overrides Property MinimumSize As Size
  293. Get
  294. Return MyBase.MinimumSize
  295. End Get
  296. Set(ByVal value As Size)
  297. MyBase.MinimumSize = value
  298. If Parent IsNot Nothing Then Parent.MinimumSize = value
  299. End Set
  300. End Property
  301.  
  302. Overrides Property MaximumSize As Size
  303. Get
  304. Return MyBase.MaximumSize
  305. End Get
  306. Set(ByVal value As Size)
  307. MyBase.MaximumSize = value
  308. If Parent IsNot Nothing Then Parent.MaximumSize = value
  309. End Set
  310. End Property
  311.  
  312. Overrides Property Text() As String
  313. Get
  314. Return MyBase.Text
  315. End Get
  316. Set(ByVal value As String)
  317. MyBase.Text = value
  318. Invalidate()
  319. End Set
  320. End Property
  321.  
  322. Overrides Property Font() As Font
  323. Get
  324. Return MyBase.Font
  325. End Get
  326. Set(ByVal value As Font)
  327. MyBase.Font = value
  328. Invalidate()
  329. End Set
  330. End Property
  331.  
  332. <Browsable(False), EditorBrowsable(EditorBrowsableState.Never), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _
  333. Overrides Property ForeColor() As Color
  334. Get
  335. Return Color.Empty
  336. End Get
  337. Set(ByVal value As Color)
  338. End Set
  339. End Property
  340. <Browsable(False), EditorBrowsable(EditorBrowsableState.Never), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _
  341. Overrides Property BackgroundImage() As Image
  342. Get
  343. Return Nothing
  344. End Get
  345. Set(ByVal value As Image)
  346. End Set
  347. End Property
  348. <Browsable(False), EditorBrowsable(EditorBrowsableState.Never), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _
  349. Overrides Property BackgroundImageLayout() As ImageLayout
  350. Get
  351. Return ImageLayout.None
  352. End Get
  353. Set(ByVal value As ImageLayout)
  354. End Set
  355. End Property
  356.  
  357. #End Region
  358.  
  359. #Region " Public Properties "
  360.  
  361. Private _SmartBounds As Boolean = True
  362. Property SmartBounds() As Boolean
  363. Get
  364. Return _SmartBounds
  365. End Get
  366. Set(ByVal value As Boolean)
  367. _SmartBounds = value
  368. End Set
  369. End Property
  370.  
  371. Private _Movable As Boolean = True
  372. Property Movable() As Boolean
  373. Get
  374. Return _Movable
  375. End Get
  376. Set(ByVal value As Boolean)
  377. _Movable = value
  378. End Set
  379. End Property
  380.  
  381. Private _Sizable As Boolean = True
  382. Property Sizable() As Boolean
  383. Get
  384. Return _Sizable
  385. End Get
  386. Set(ByVal value As Boolean)
  387. _Sizable = value
  388. End Set
  389. End Property
  390.  
  391. Private _TransparencyKey As Color
  392. Property TransparencyKey() As Color
  393. Get
  394. If _IsParentForm AndAlso Not _ControlMode Then Return ParentForm.TransparencyKey Else Return _TransparencyKey
  395. End Get
  396. Set(ByVal value As Color)
  397. If value = _TransparencyKey Then Return
  398. _TransparencyKey = value
  399.  
  400. If _IsParentForm AndAlso Not _ControlMode Then
  401. ParentForm.TransparencyKey = value
  402. ColorHook()
  403. End If
  404. End Set
  405. End Property
  406.  
  407. Private _BorderStyle As FormBorderStyle
  408. Property BorderStyle() As FormBorderStyle
  409. Get
  410. If _IsParentForm AndAlso Not _ControlMode Then Return ParentForm.FormBorderStyle Else Return _BorderStyle
  411. End Get
  412. Set(ByVal value As FormBorderStyle)
  413. _BorderStyle = value
  414.  
  415. If _IsParentForm AndAlso Not _ControlMode Then
  416. ParentForm.FormBorderStyle = value
  417.  
  418. If Not value = FormBorderStyle.None Then
  419. Movable = False
  420. Sizable = False
  421. End If
  422. End If
  423. End Set
  424. End Property
  425.  
  426. Private _NoRounding As Boolean
  427. Property NoRounding() As Boolean
  428. Get
  429. Return _NoRounding
  430. End Get
  431. Set(ByVal v As Boolean)
  432. _NoRounding = v
  433. Invalidate()
  434. End Set
  435. End Property
  436.  
  437. Private _Image As Image
  438. Property Image() As Image
  439. Get
  440. Return _Image
  441. End Get
  442. Set(ByVal value As Image)
  443. If value Is Nothing Then _ImageSize = Size.Empty Else _ImageSize = value.Size
  444.  
  445. _Image = value
  446. Invalidate()
  447. End Set
  448. End Property
  449.  
  450. Private Items As New Dictionary(Of String, Color)
  451. Property Colors() As Bloom()
  452. Get
  453. Dim T As New List(Of Bloom)
  454. Dim E As Dictionary(Of String, Color).Enumerator = Items.GetEnumerator
  455.  
  456. While E.MoveNext
  457. T.Add(New Bloom(E.Current.Key, E.Current.Value))
  458. End While
  459.  
  460. Return T.ToArray
  461. End Get
  462. Set(ByVal value As Bloom())
  463. For Each B As Bloom In value
  464. If Items.ContainsKey(B.Name) Then Items(B.Name) = B.Value
  465. Next
  466.  
  467. InvalidateCustimization()
  468. ColorHook()
  469. Invalidate()
  470. End Set
  471. End Property
  472.  
  473. Private _Customization As String
  474. Property Customization() As String
  475. Get
  476. Return _Customization
  477. End Get
  478. Set(ByVal value As String)
  479. If value = _Customization Then Return
  480.  
  481. Dim Data As Byte()
  482. Dim Items As Bloom() = Colors
  483.  
  484. Try
  485. Data = Convert.FromBase64String(value)
  486. For I As Integer = 0 To Items.Length - 1
  487. Items(I).Value = Color.FromArgb(BitConverter.ToInt32(Data, I * 4))
  488. Next
  489. Catch
  490. Return
  491. End Try
  492.  
  493. _Customization = value
  494.  
  495. Colors = Items
  496. ColorHook()
  497. Invalidate()
  498. End Set
  499. End Property
  500.  
  501. Private _Transparent As Boolean
  502. Property Transparent() As Boolean
  503. Get
  504. Return _Transparent
  505. End Get
  506. Set(ByVal value As Boolean)
  507. _Transparent = value
  508. If Not (IsHandleCreated OrElse _ControlMode) Then Return
  509.  
  510. If Not value AndAlso Not BackColor.A = 255 Then
  511. Throw New Exception("Unable to change value to false while a transparent BackColor is in use.")
  512. End If
  513.  
  514. SetStyle(ControlStyles.Opaque, Not value)
  515. SetStyle(ControlStyles.SupportsTransparentBackColor, value)
  516.  
  517. InvalidateBitmap()
  518. Invalidate()
  519. End Set
  520. End Property
  521.  
  522. #End Region
  523.  
  524. #Region " Private Properties "
  525.  
  526. Private _ImageSize As Size
  527. Protected ReadOnly Property ImageSize() As Size
  528. Get
  529. Return _ImageSize
  530. End Get
  531. End Property
  532.  
  533. Private _IsParentForm As Boolean
  534. Protected ReadOnly Property IsParentForm As Boolean
  535. Get
  536. Return _IsParentForm
  537. End Get
  538. End Property
  539.  
  540. Protected ReadOnly Property IsParentMdi As Boolean
  541. Get
  542. If Parent Is Nothing Then Return False
  543. Return Parent.Parent IsNot Nothing
  544. End Get
  545. End Property
  546.  
  547. Private _LockWidth As Integer
  548. Protected Property LockWidth() As Integer
  549. Get
  550. Return _LockWidth
  551. End Get
  552. Set(ByVal value As Integer)
  553. _LockWidth = value
  554. If Not LockWidth = 0 AndAlso IsHandleCreated Then Width = LockWidth
  555. End Set
  556. End Property
  557.  
  558. Private _LockHeight As Integer
  559. Protected Property LockHeight() As Integer
  560. Get
  561. Return _LockHeight
  562. End Get
  563. Set(ByVal value As Integer)
  564. _LockHeight = value
  565. If Not LockHeight = 0 AndAlso IsHandleCreated Then Height = LockHeight
  566. End Set
  567. End Property
  568.  
  569. Private _Header As Integer = 24
  570. Protected Property Header() As Integer
  571. Get
  572. Return _Header
  573. End Get
  574. Set(ByVal v As Integer)
  575. _Header = v
  576.  
  577. If Not _ControlMode Then
  578. Frame = New Rectangle(7, 7, Width - 14, v - 7)
  579. Invalidate()
  580. End If
  581. End Set
  582. End Property
  583.  
  584. Private _ControlMode As Boolean
  585. Protected Property ControlMode() As Boolean
  586. Get
  587. Return _ControlMode
  588. End Get
  589. Set(ByVal v As Boolean)
  590. _ControlMode = v
  591.  
  592. Transparent = _Transparent
  593. If _Transparent AndAlso _BackColor Then BackColor = Color.Transparent
  594.  
  595. InvalidateBitmap()
  596. Invalidate()
  597. End Set
  598. End Property
  599.  
  600. #End Region
  601.  
  602.  
  603. #Region " Property Helpers "
  604.  
  605. Protected Function GetPen(ByVal name As String) As Pen
  606. Return New Pen(Items(name))
  607. End Function
  608. Protected Function GetPen(ByVal name As String, ByVal width As Single) As Pen
  609. Return New Pen(Items(name), width)
  610. End Function
  611.  
  612. Protected Function GetBrush(ByVal name As String) As SolidBrush
  613. Return New SolidBrush(Items(name))
  614. End Function
  615.  
  616. Protected Function GetColor(ByVal name As String) As Color
  617. Return Items(name)
  618. End Function
  619.  
  620. Protected Sub SetColor(ByVal name As String, ByVal value As Color)
  621. If Items.ContainsKey(name) Then Items(name) = value Else Items.Add(name, value)
  622. End Sub
  623. Protected Sub SetColor(ByVal name As String, ByVal r As Byte, ByVal g As Byte, ByVal b As Byte)
  624. SetColor(name, Color.FromArgb(r, g, b))
  625. End Sub
  626. Protected Sub SetColor(ByVal name As String, ByVal a As Byte, ByVal r As Byte, ByVal g As Byte, ByVal b As Byte)
  627. SetColor(name, Color.FromArgb(a, r, g, b))
  628. End Sub
  629. Protected Sub SetColor(ByVal name As String, ByVal a As Byte, ByVal value As Color)
  630. SetColor(name, Color.FromArgb(a, value))
  631. End Sub
  632.  
  633. Private Sub InvalidateBitmap()
  634. If _Transparent AndAlso _ControlMode Then
  635. If Width = 0 OrElse Height = 0 Then Return
  636. B = New Bitmap(Width, Height, PixelFormat.Format32bppPArgb)
  637. G = Graphics.FromImage(B)
  638. Else
  639. G = Nothing
  640. B = Nothing
  641. End If
  642. End Sub
  643.  
  644. Private Sub InvalidateCustimization()
  645. Dim M As New MemoryStream(Items.Count * 4)
  646.  
  647. For Each B As Bloom In Colors
  648. M.Write(BitConverter.GetBytes(B.Value.ToArgb), 0, 4)
  649. Next
  650.  
  651. M.Close()
  652. _Customization = Convert.ToBase64String(M.ToArray)
  653. End Sub
  654.  
  655. #End Region
  656.  
  657.  
  658. #Region " User Hooks "
  659.  
  660. Protected MustOverride Sub ColorHook()
  661. Protected MustOverride Sub PaintHook()
  662.  
  663. Protected Overridable Sub OnCreation()
  664. End Sub
  665.  
  666. #End Region
  667.  
  668.  
  669. #Region " Offset "
  670.  
  671. Private OffsetReturnRectangle As Rectangle
  672. Protected Function Offset(ByVal r As Rectangle, ByVal amount As Integer) As Rectangle
  673. OffsetReturnRectangle = New Rectangle(r.X + amount, r.Y + amount, r.Width - (amount * 2), r.Height - (amount * 2))
  674. Return OffsetReturnRectangle
  675. End Function
  676.  
  677. Private OffsetReturnSize As Size
  678. Protected Function Offset(ByVal s As Size, ByVal amount As Integer) As Size
  679. OffsetReturnSize = New Size(s.Width + amount, s.Height + amount)
  680. Return OffsetReturnSize
  681. End Function
  682.  
  683. Private OffsetReturnPoint As Point
  684. Protected Function Offset(ByVal p As Point, ByVal amount As Integer) As Point
  685. OffsetReturnPoint = New Point(p.X + amount, p.Y + amount)
  686. Return OffsetReturnPoint
  687. End Function
  688.  
  689. #End Region
  690.  
  691. #Region " Center "
  692.  
  693. Private CenterReturn As Point
  694.  
  695. Protected Function Center(ByVal p As Rectangle, ByVal c As Rectangle) As Point
  696. CenterReturn = New Point((p.Width \ 2 - c.Width \ 2) + p.X + c.X, (p.Height \ 2 - c.Height \ 2) + p.Y + c.Y)
  697. Return CenterReturn
  698. End Function
  699. Protected Function Center(ByVal p As Rectangle, ByVal c As Size) As Point
  700. CenterReturn = New Point((p.Width \ 2 - c.Width \ 2) + p.X, (p.Height \ 2 - c.Height \ 2) + p.Y)
  701. Return CenterReturn
  702. End Function
  703.  
  704. Protected Function Center(ByVal child As Rectangle) As Point
  705. Return Center(Width, Height, child.Width, child.Height)
  706. End Function
  707. Protected Function Center(ByVal child As Size) As Point
  708. Return Center(Width, Height, child.Width, child.Height)
  709. End Function
  710. Protected Function Center(ByVal childWidth As Integer, ByVal childHeight As Integer) As Point
  711. Return Center(Width, Height, childWidth, childHeight)
  712. End Function
  713.  
  714. Protected Function Center(ByVal p As Size, ByVal c As Size) As Point
  715. Return Center(p.Width, p.Height, c.Width, c.Height)
  716. End Function
  717.  
  718. Protected Function Center(ByVal pWidth As Integer, ByVal pHeight As Integer, ByVal cWidth As Integer, ByVal cHeight As Integer) As Point
  719. CenterReturn = New Point(pWidth \ 2 - cWidth \ 2, pHeight \ 2 - cHeight \ 2)
  720. Return CenterReturn
  721. End Function
  722.  
  723. #End Region
  724.  
  725. #Region " Measure "
  726.  
  727. Private MeasureBitmap As Bitmap
  728. Private MeasureGraphics As Graphics 'TODO: Potential issues during multi-threading.
  729.  
  730. Protected Function Measure() As Size
  731. Return MeasureGraphics.MeasureString(Text, Font, Width).ToSize
  732. End Function
  733. Protected Function Measure(ByVal text As String) As Size
  734. Return MeasureGraphics.MeasureString(text, Font, Width).ToSize
  735. End Function
  736.  
  737. #End Region
  738.  
  739.  
  740. #Region " DrawPixel "
  741.  
  742. Private DrawPixelBrush As SolidBrush
  743.  
  744. Protected Sub DrawPixel(ByVal c1 As Color, ByVal x As Integer, ByVal y As Integer)
  745. If _Transparent Then
  746. B.SetPixel(x, y, c1)
  747. Else
  748. DrawPixelBrush = New SolidBrush(c1)
  749. G.FillRectangle(DrawPixelBrush, x, y, 1, 1)
  750. End If
  751. End Sub
  752.  
  753. #End Region
  754.  
  755. #Region " DrawCorners "
  756.  
  757. Private DrawCornersBrush As SolidBrush
  758.  
  759. Protected Sub DrawCorners(ByVal c1 As Color, ByVal offset As Integer)
  760. DrawCorners(c1, 0, 0, Width, Height, offset)
  761. End Sub
  762. Protected Sub DrawCorners(ByVal c1 As Color, ByVal r1 As Rectangle, ByVal offset As Integer)
  763. DrawCorners(c1, r1.X, r1.Y, r1.Width, r1.Height, offset)
  764. End Sub
  765. Protected Sub DrawCorners(ByVal c1 As Color, ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer, ByVal offset As Integer)
  766. DrawCorners(c1, x + offset, y + offset, width - (offset * 2), height - (offset * 2))
  767. End Sub
  768.  
  769. Protected Sub DrawCorners(ByVal c1 As Color)
  770. DrawCorners(c1, 0, 0, Width, Height)
  771. End Sub
  772. Protected Sub DrawCorners(ByVal c1 As Color, ByVal r1 As Rectangle)
  773. DrawCorners(c1, r1.X, r1.Y, r1.Width, r1.Height)
  774. End Sub
  775. Protected Sub DrawCorners(ByVal c1 As Color, ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer)
  776. If _NoRounding Then Return
  777.  
  778. If _Transparent Then
  779. B.SetPixel(x, y, c1)
  780. B.SetPixel(x + (width - 1), y, c1)
  781. B.SetPixel(x, y + (height - 1), c1)
  782. B.SetPixel(x + (width - 1), y + (height - 1), c1)
  783. Else
  784. DrawCornersBrush = New SolidBrush(c1)
  785. G.FillRectangle(DrawCornersBrush, x, y, 1, 1)
  786. G.FillRectangle(DrawCornersBrush, x + (width - 1), y, 1, 1)
  787. G.FillRectangle(DrawCornersBrush, x, y + (height - 1), 1, 1)
  788. G.FillRectangle(DrawCornersBrush, x + (width - 1), y + (height - 1), 1, 1)
  789. End If
  790. End Sub
  791.  
  792. #End Region
  793.  
  794. #Region " DrawBorders "
  795.  
  796. Protected Sub DrawBorders(ByVal p1 As Pen, ByVal offset As Integer)
  797. DrawBorders(p1, 0, 0, Width, Height, offset)
  798. End Sub
  799. Protected Sub DrawBorders(ByVal p1 As Pen, ByVal r As Rectangle, ByVal offset As Integer)
  800. DrawBorders(p1, r.X, r.Y, r.Width, r.Height, offset)
  801. End Sub
  802. 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)
  803. DrawBorders(p1, x + offset, y + offset, width - (offset * 2), height - (offset * 2))
  804. End Sub
  805.  
  806. Protected Sub DrawBorders(ByVal p1 As Pen)
  807. DrawBorders(p1, 0, 0, Width, Height)
  808. End Sub
  809. Protected Sub DrawBorders(ByVal p1 As Pen, ByVal r As Rectangle)
  810. DrawBorders(p1, r.X, r.Y, r.Width, r.Height)
  811. End Sub
  812. Protected Sub DrawBorders(ByVal p1 As Pen, ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer)
  813. G.DrawRectangle(p1, x, y, width - 1, height - 1)
  814. End Sub
  815.  
  816. #End Region
  817.  
  818. #Region " DrawText "
  819.  
  820. Private DrawTextPoint As Point
  821. Private DrawTextSize As Size
  822.  
  823. Protected Sub DrawText(ByVal b1 As Brush, ByVal a As HorizontalAlignment, ByVal x As Integer, ByVal y As Integer)
  824. DrawText(b1, Text, a, x, y)
  825. End Sub
  826. Protected Sub DrawText(ByVal b1 As Brush, ByVal text As String, ByVal a As HorizontalAlignment, ByVal x As Integer, ByVal y As Integer)
  827. If text.Length = 0 Then Return
  828.  
  829. DrawTextSize = Measure(text)
  830. DrawTextPoint = New Point(Width \ 2 - DrawTextSize.Width \ 2, Header \ 2 - DrawTextSize.Height \ 2)
  831.  
  832. Select Case a
  833. Case HorizontalAlignment.Left
  834. G.DrawString(text, Font, b1, x, DrawTextPoint.Y + y)
  835. Case HorizontalAlignment.Center
  836. G.DrawString(text, Font, b1, DrawTextPoint.X + x, DrawTextPoint.Y + y)
  837. Case HorizontalAlignment.Right
  838. G.DrawString(text, Font, b1, Width - DrawTextSize.Width - x, DrawTextPoint.Y + y)
  839. End Select
  840. End Sub
  841.  
  842. Protected Sub DrawText(ByVal b1 As Brush, ByVal p1 As Point)
  843. If Text.Length = 0 Then Return
  844. G.DrawString(Text, Font, b1, p1)
  845. End Sub
  846. Protected Sub DrawText(ByVal b1 As Brush, ByVal x As Integer, ByVal y As Integer)
  847. If Text.Length = 0 Then Return
  848. G.DrawString(Text, Font, b1, x, y)
  849. End Sub
  850.  
  851. #End Region
  852.  
  853. #Region " DrawImage "
  854.  
  855. Private DrawImagePoint As Point
  856.  
  857. Protected Sub DrawImage(ByVal a As HorizontalAlignment, ByVal x As Integer, ByVal y As Integer)
  858. DrawImage(_Image, a, x, y)
  859. End Sub
  860. Protected Sub DrawImage(ByVal image As Image, ByVal a As HorizontalAlignment, ByVal x As Integer, ByVal y As Integer)
  861. If image Is Nothing Then Return
  862. DrawImagePoint = New Point(Width \ 2 - image.Width \ 2, Header \ 2 - image.Height \ 2)
  863.  
  864. Select Case a
  865. Case HorizontalAlignment.Left
  866. G.DrawImage(image, x, DrawImagePoint.Y + y, image.Width, image.Height)
  867. Case HorizontalAlignment.Center
  868. G.DrawImage(image, DrawImagePoint.X + x, DrawImagePoint.Y + y, image.Width, image.Height)
  869. Case HorizontalAlignment.Right
  870. G.DrawImage(image, Width - image.Width - x, DrawImagePoint.Y + y, image.Width, image.Height)
  871. End Select
  872. End Sub
  873.  
  874. Protected Sub DrawImage(ByVal p1 As Point)
  875. DrawImage(_Image, p1.X, p1.Y)
  876. End Sub
  877. Protected Sub DrawImage(ByVal x As Integer, ByVal y As Integer)
  878. DrawImage(_Image, x, y)
  879. End Sub
  880.  
  881. Protected Sub DrawImage(ByVal image As Image, ByVal p1 As Point)
  882. DrawImage(image, p1.X, p1.Y)
  883. End Sub
  884. Protected Sub DrawImage(ByVal image As Image, ByVal x As Integer, ByVal y As Integer)
  885. If image Is Nothing Then Return
  886. G.DrawImage(image, x, y, image.Width, image.Height)
  887. End Sub
  888.  
  889. #End Region
  890.  
  891. #Region " DrawGradient "
  892.  
  893. Private DrawGradientBrush As LinearGradientBrush
  894. Private DrawGradientRectangle As Rectangle
  895.  
  896. Protected Sub DrawGradient(ByVal blend As ColorBlend, ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer)
  897. DrawGradientRectangle = New Rectangle(x, y, width, height)
  898. DrawGradient(blend, DrawGradientRectangle)
  899. End Sub
  900. 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)
  901. DrawGradientRectangle = New Rectangle(x, y, width, height)
  902. DrawGradient(blend, DrawGradientRectangle, angle)
  903. End Sub
  904.  
  905. Protected Sub DrawGradient(ByVal blend As ColorBlend, ByVal r As Rectangle)
  906. DrawGradientBrush = New LinearGradientBrush(r, Color.Empty, Color.Empty, 90.0F)
  907. DrawGradientBrush.InterpolationColors = blend
  908. G.FillRectangle(DrawGradientBrush, r)
  909. End Sub
  910. Protected Sub DrawGradient(ByVal blend As ColorBlend, ByVal r As Rectangle, ByVal angle As Single)
  911. DrawGradientBrush = New LinearGradientBrush(r, Color.Empty, Color.Empty, angle)
  912. DrawGradientBrush.InterpolationColors = blend
  913. G.FillRectangle(DrawGradientBrush, r)
  914. End Sub
  915.  
  916.  
  917. 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)
  918. DrawGradientRectangle = New Rectangle(x, y, width, height)
  919. DrawGradient(c1, c2, DrawGradientRectangle)
  920. End Sub
  921. 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)
  922. DrawGradientRectangle = New Rectangle(x, y, width, height)
  923. DrawGradient(c1, c2, DrawGradientRectangle, angle)
  924. End Sub
  925.  
  926. Protected Sub DrawGradient(ByVal c1 As Color, ByVal c2 As Color, ByVal r As Rectangle)
  927. DrawGradientBrush = New LinearGradientBrush(r, c1, c2, 90.0F)
  928. G.FillRectangle(DrawGradientBrush, r)
  929. End Sub
  930. Protected Sub DrawGradient(ByVal c1 As Color, ByVal c2 As Color, ByVal r As Rectangle, ByVal angle As Single)
  931. DrawGradientBrush = New LinearGradientBrush(r, c1, c2, angle)
  932. G.FillRectangle(DrawGradientBrush, r)
  933. End Sub
  934.  
  935. #End Region
  936.  
  937. #Region " DrawRadial "
  938.  
  939. Private DrawRadialPath As GraphicsPath
  940. Private DrawRadialBrush1 As PathGradientBrush
  941. Private DrawRadialBrush2 As LinearGradientBrush
  942. Private DrawRadialRectangle As Rectangle
  943.  
  944. Sub DrawRadial(ByVal blend As ColorBlend, ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer)
  945. DrawRadialRectangle = New Rectangle(x, y, width, height)
  946. DrawRadial(blend, DrawRadialRectangle, width \ 2, height \ 2)
  947. End Sub
  948. Sub DrawRadial(ByVal blend As ColorBlend, ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer, ByVal center As Point)
  949. DrawRadialRectangle = New Rectangle(x, y, width, height)
  950. DrawRadial(blend, DrawRadialRectangle, center.X, center.Y)
  951. End Sub
  952. Sub DrawRadial(ByVal blend As ColorBlend, ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer, ByVal cx As Integer, ByVal cy As Integer)
  953. DrawRadialRectangle = New Rectangle(x, y, width, height)
  954. DrawRadial(blend, DrawRadialRectangle, cx, cy)
  955. End Sub
  956.  
  957. Sub DrawRadial(ByVal blend As ColorBlend, ByVal r As Rectangle)
  958. DrawRadial(blend, r, r.Width \ 2, r.Height \ 2)
  959. End Sub
  960. Sub DrawRadial(ByVal blend As ColorBlend, ByVal r As Rectangle, ByVal center As Point)
  961. DrawRadial(blend, r, center.X, center.Y)
  962. End Sub
  963. Sub DrawRadial(ByVal blend As ColorBlend, ByVal r As Rectangle, ByVal cx As Integer, ByVal cy As Integer)
  964. DrawRadialPath.Reset()
  965. DrawRadialPath.AddEllipse(r.X, r.Y, r.Width - 1, r.Height - 1)
  966.  
  967. DrawRadialBrush1 = New PathGradientBrush(DrawRadialPath)
  968. DrawRadialBrush1.CenterPoint = New Point(r.X + cx, r.Y + cy)
  969. DrawRadialBrush1.InterpolationColors = blend
  970.  
  971. If G.SmoothingMode = SmoothingMode.AntiAlias Then
  972. G.FillEllipse(DrawRadialBrush1, r.X + 1, r.Y + 1, r.Width - 3, r.Height - 3)
  973. Else
  974. G.FillEllipse(DrawRadialBrush1, r)
  975. End If
  976. End Sub
  977.  
  978.  
  979. Protected Sub DrawRadial(ByVal c1 As Color, ByVal c2 As Color, ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer)
  980. DrawRadialRectangle = New Rectangle(x, y, width, height)
  981. DrawRadial(c1, c2, DrawGradientRectangle)
  982. End Sub
  983. Protected Sub DrawRadial(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)
  984. DrawRadialRectangle = New Rectangle(x, y, width, height)
  985. DrawRadial(c1, c2, DrawGradientRectangle, angle)
  986. End Sub
  987.  
  988. Protected Sub DrawRadial(ByVal c1 As Color, ByVal c2 As Color, ByVal r As Rectangle)
  989. DrawRadialBrush2 = New LinearGradientBrush(r, c1, c2, 90.0F)
  990. G.FillRectangle(DrawGradientBrush, r)
  991. End Sub
  992. Protected Sub DrawRadial(ByVal c1 As Color, ByVal c2 As Color, ByVal r As Rectangle, ByVal angle As Single)
  993. DrawRadialBrush2 = New LinearGradientBrush(r, c1, c2, angle)
  994. G.FillEllipse(DrawGradientBrush, r)
  995. End Sub
  996.  
  997. #End Region
  998.  
  999. End Class
  1000.  
  1001. MustInherit Class ThemeControl153
  1002. Inherits Control
  1003.  
  1004.  
  1005. #Region " Initialization "
  1006.  
  1007. Protected G As Graphics, B As Bitmap
  1008.  
  1009. Sub New()
  1010. SetStyle(DirectCast(139270, ControlStyles), True)
  1011.  
  1012. _ImageSize = Size.Empty
  1013. Font = New Font("Verdana", 8S)
  1014.  
  1015. MeasureBitmap = New Bitmap(1, 1)
  1016. MeasureGraphics = Graphics.FromImage(MeasureBitmap)
  1017.  
  1018. DrawRadialPath = New GraphicsPath
  1019.  
  1020. InvalidateCustimization() 'Remove?
  1021. End Sub
  1022.  
  1023. Protected NotOverridable Overrides Sub OnHandleCreated(ByVal e As EventArgs)
  1024. InvalidateCustimization()
  1025. ColorHook()
  1026.  
  1027. If Not _LockWidth = 0 Then Width = _LockWidth
  1028. If Not _LockHeight = 0 Then Height = _LockHeight
  1029.  
  1030. Transparent = _Transparent
  1031. If _Transparent AndAlso _BackColor Then BackColor = Color.Transparent
  1032.  
  1033. MyBase.OnHandleCreated(e)
  1034. End Sub
  1035.  
  1036. Protected NotOverridable Overrides Sub OnParentChanged(ByVal e As EventArgs)
  1037. If Parent IsNot Nothing Then OnCreation()
  1038. MyBase.OnParentChanged(e)
  1039. End Sub
  1040.  
  1041. #End Region
  1042.  
  1043.  
  1044. Protected NotOverridable Overrides Sub OnPaint(ByVal e As PaintEventArgs)
  1045. If Width = 0 OrElse Height = 0 Then Return
  1046.  
  1047. If _Transparent Then
  1048. PaintHook()
  1049. e.Graphics.DrawImage(B, 0, 0)
  1050. Else
  1051. G = e.Graphics
  1052. PaintHook()
  1053. End If
  1054. End Sub
  1055.  
  1056.  
  1057. #Region " Size Handling "
  1058.  
  1059. Protected NotOverridable Overrides Sub OnSizeChanged(ByVal e As EventArgs)
  1060. If _Transparent Then
  1061. InvalidateBitmap()
  1062. End If
  1063.  
  1064. Invalidate()
  1065. MyBase.OnSizeChanged(e)
  1066. End Sub
  1067.  
  1068. Protected Overrides Sub SetBoundsCore(ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer, ByVal specified As BoundsSpecified)
  1069. If Not _LockWidth = 0 Then width = _LockWidth
  1070. If Not _LockHeight = 0 Then height = _LockHeight
  1071. MyBase.SetBoundsCore(x, y, width, height, specified)
  1072. End Sub
  1073.  
  1074. #End Region
  1075.  
  1076. #Region " State Handling "
  1077.  
  1078. Private InPosition As Boolean
  1079. Protected Overrides Sub OnMouseEnter(ByVal e As EventArgs)
  1080. InPosition = True
  1081. SetState(MouseState.Over)
  1082. MyBase.OnMouseEnter(e)
  1083. End Sub
  1084.  
  1085. Protected Overrides Sub OnMouseUp(ByVal e As MouseEventArgs)
  1086. If InPosition Then SetState(MouseState.Over)
  1087. MyBase.OnMouseUp(e)
  1088. End Sub
  1089.  
  1090. Protected Overrides Sub OnMouseDown(ByVal e As MouseEventArgs)
  1091. If e.Button = Windows.Forms.MouseButtons.Left Then SetState(MouseState.Down)
  1092. MyBase.OnMouseDown(e)
  1093. End Sub
  1094.  
  1095. Protected Overrides Sub OnMouseLeave(ByVal e As EventArgs)
  1096. InPosition = False
  1097. SetState(MouseState.None)
  1098. MyBase.OnMouseLeave(e)
  1099. End Sub
  1100.  
  1101. Protected Overrides Sub OnEnabledChanged(ByVal e As EventArgs)
  1102. If Enabled Then SetState(MouseState.None) Else SetState(MouseState.Block)
  1103. MyBase.OnEnabledChanged(e)
  1104. End Sub
  1105.  
  1106. Protected State As MouseState
  1107. Private Sub SetState(ByVal current As MouseState)
  1108. State = current
  1109. Invalidate()
  1110. End Sub
  1111.  
  1112. #End Region
  1113.  
  1114.  
  1115. #Region " Base Properties "
  1116.  
  1117. <Browsable(False), EditorBrowsable(EditorBrowsableState.Never), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _
  1118. Overrides Property ForeColor() As Color
  1119. Get
  1120. Return Color.Empty
  1121. End Get
  1122. Set(ByVal value As Color)
  1123. End Set
  1124. End Property
  1125. <Browsable(False), EditorBrowsable(EditorBrowsableState.Never), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _
  1126. Overrides Property BackgroundImage() As Image
  1127. Get
  1128. Return Nothing
  1129. End Get
  1130. Set(ByVal value As Image)
  1131. End Set
  1132. End Property
  1133. <Browsable(False), EditorBrowsable(EditorBrowsableState.Never), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _
  1134. Overrides Property BackgroundImageLayout() As ImageLayout
  1135. Get
  1136. Return ImageLayout.None
  1137. End Get
  1138. Set(ByVal value As ImageLayout)
  1139. End Set
  1140. End Property
  1141.  
  1142. Overrides Property Text() As String
  1143. Get
  1144. Return MyBase.Text
  1145. End Get
  1146. Set(ByVal value As String)
  1147. MyBase.Text = value
  1148. Invalidate()
  1149. End Set
  1150. End Property
  1151. Overrides Property Font() As Font
  1152. Get
  1153. Return MyBase.Font
  1154. End Get
  1155. Set(ByVal value As Font)
  1156. MyBase.Font = value
  1157. Invalidate()
  1158. End Set
  1159. End Property
  1160.  
  1161. Private _BackColor As Boolean
  1162. <Category("Misc")> _
  1163. Overrides Property BackColor() As Color
  1164. Get
  1165. Return MyBase.BackColor
  1166. End Get
  1167. Set(ByVal value As Color)
  1168. If Not IsHandleCreated AndAlso value = Color.Transparent Then
  1169. _BackColor = True
  1170. Return
  1171. End If
  1172.  
  1173. MyBase.BackColor = value
  1174. If Parent IsNot Nothing Then ColorHook()
  1175. End Set
  1176. End Property
  1177.  
  1178. #End Region
  1179.  
  1180. #Region " Public Properties "
  1181.  
  1182. Private _NoRounding As Boolean
  1183. Property NoRounding() As Boolean
  1184. Get
  1185. Return _NoRounding
  1186. End Get
  1187. Set(ByVal v As Boolean)
  1188. _NoRounding = v
  1189. Invalidate()
  1190. End Set
  1191. End Property
  1192.  
  1193. Private _Image As Image
  1194. Property Image() As Image
  1195. Get
  1196. Return _Image
  1197. End Get
  1198. Set(ByVal value As Image)
  1199. If value Is Nothing Then
  1200. _ImageSize = Size.Empty
  1201. Else
  1202. _ImageSize = value.Size
  1203. End If
  1204.  
  1205. _Image = value
  1206. Invalidate()
  1207. End Set
  1208. End Property
  1209.  
  1210. Private _Transparent As Boolean
  1211. Property Transparent() As Boolean
  1212. Get
  1213. Return _Transparent
  1214. End Get
  1215. Set(ByVal value As Boolean)
  1216. _Transparent = value
  1217. If Not IsHandleCreated Then Return
  1218.  
  1219. If Not value AndAlso Not BackColor.A = 255 Then
  1220. Throw New Exception("Unable to change value to false while a transparent BackColor is in use.")
  1221. End If
  1222.  
  1223. SetStyle(ControlStyles.Opaque, Not value)
  1224. SetStyle(ControlStyles.SupportsTransparentBackColor, value)
  1225.  
  1226. If value Then InvalidateBitmap() Else B = Nothing
  1227. Invalidate()
  1228. End Set
  1229. End Property
  1230.  
  1231. Private Items As New Dictionary(Of String, Color)
  1232. Property Colors() As Bloom()
  1233. Get
  1234. Dim T As New List(Of Bloom)
  1235. Dim E As Dictionary(Of String, Color).Enumerator = Items.GetEnumerator
  1236.  
  1237. While E.MoveNext
  1238. T.Add(New Bloom(E.Current.Key, E.Current.Value))
  1239. End While
  1240.  
  1241. Return T.ToArray
  1242. End Get
  1243. Set(ByVal value As Bloom())
  1244. For Each B As Bloom In value
  1245. If Items.ContainsKey(B.Name) Then Items(B.Name) = B.Value
  1246. Next
  1247.  
  1248. InvalidateCustimization()
  1249. ColorHook()
  1250. Invalidate()
  1251. End Set
  1252. End Property
  1253.  
  1254. Private _Customization As String
  1255. Property Customization() As String
  1256. Get
  1257. Return _Customization
  1258. End Get
  1259. Set(ByVal value As String)
  1260. If value = _Customization Then Return
  1261.  
  1262. Dim Data As Byte()
  1263. Dim Items As Bloom() = Colors
  1264.  
  1265. Try
  1266. Data = Convert.FromBase64String(value)
  1267. For I As Integer = 0 To Items.Length - 1
  1268. Items(I).Value = Color.FromArgb(BitConverter.ToInt32(Data, I * 4))
  1269. Next
  1270. Catch
  1271. Return
  1272. End Try
  1273.  
  1274. _Customization = value
  1275.  
  1276. Colors = Items
  1277. ColorHook()
  1278. Invalidate()
  1279. End Set
  1280. End Property
  1281.  
  1282. #End Region
  1283.  
  1284. #Region " Private Properties "
  1285.  
  1286. Private _ImageSize As Size
  1287. Protected ReadOnly Property ImageSize() As Size
  1288. Get
  1289. Return _ImageSize
  1290. End Get
  1291. End Property
  1292.  
  1293. Private _LockWidth As Integer
  1294. Protected Property LockWidth() As Integer
  1295. Get
  1296. Return _LockWidth
  1297. End Get
  1298. Set(ByVal value As Integer)
  1299. _LockWidth = value
  1300. If Not LockWidth = 0 AndAlso IsHandleCreated Then Width = LockWidth
  1301. End Set
  1302. End Property
  1303.  
  1304. Private _LockHeight As Integer
  1305. Protected Property LockHeight() As Integer
  1306. Get
  1307. Return _LockHeight
  1308. End Get
  1309. Set(ByVal value As Integer)
  1310. _LockHeight = value
  1311. If Not LockHeight = 0 AndAlso IsHandleCreated Then Height = LockHeight
  1312. End Set
  1313. End Property
  1314.  
  1315. #End Region
  1316.  
  1317.  
  1318. #Region " Property Helpers "
  1319.  
  1320. Protected Function GetPen(ByVal name As String) As Pen
  1321. Return New Pen(Items(name))
  1322. End Function
  1323. Protected Function GetPen(ByVal name As String, ByVal width As Single) As Pen
  1324. Return New Pen(Items(name), width)
  1325. End Function
  1326.  
  1327. Protected Function GetBrush(ByVal name As String) As SolidBrush
  1328. Return New SolidBrush(Items(name))
  1329. End Function
  1330.  
  1331. Protected Function GetColor(ByVal name As String) As Color
  1332. Return Items(name)
  1333. End Function
  1334.  
  1335. Protected Sub SetColor(ByVal name As String, ByVal value As Color)
  1336. If Items.ContainsKey(name) Then Items(name) = value Else Items.Add(name, value)
  1337. End Sub
  1338. Protected Sub SetColor(ByVal name As String, ByVal r As Byte, ByVal g As Byte, ByVal b As Byte)
  1339. SetColor(name, Color.FromArgb(r, g, b))
  1340. End Sub
  1341. Protected Sub SetColor(ByVal name As String, ByVal a As Byte, ByVal r As Byte, ByVal g As Byte, ByVal b As Byte)
  1342. SetColor(name, Color.FromArgb(a, r, g, b))
  1343. End Sub
  1344. Protected Sub SetColor(ByVal name As String, ByVal a As Byte, ByVal value As Color)
  1345. SetColor(name, Color.FromArgb(a, value))
  1346. End Sub
  1347.  
  1348. Private Sub InvalidateBitmap()
  1349. If Width = 0 OrElse Height = 0 Then Return
  1350. B = New Bitmap(Width, Height, PixelFormat.Format32bppPArgb)
  1351. G = Graphics.FromImage(B)
  1352. End Sub
  1353.  
  1354. Private Sub InvalidateCustimization()
  1355. Dim M As New MemoryStream(Items.Count * 4)
  1356.  
  1357. For Each B As Bloom In Colors
  1358. M.Write(BitConverter.GetBytes(B.Value.ToArgb), 0, 4)
  1359. Next
  1360.  
  1361. M.Close()
  1362. _Customization = Convert.ToBase64String(M.ToArray)
  1363. End Sub
  1364.  
  1365. #End Region
  1366.  
  1367.  
  1368. #Region " User Hooks "
  1369.  
  1370. Protected MustOverride Sub ColorHook()
  1371. Protected MustOverride Sub PaintHook()
  1372.  
  1373. Protected Overridable Sub OnCreation()
  1374. End Sub
  1375.  
  1376. #End Region
  1377.  
  1378.  
  1379. #Region " Offset "
  1380.  
  1381. Private OffsetReturnRectangle As Rectangle
  1382. Protected Function Offset(ByVal r As Rectangle, ByVal amount As Integer) As Rectangle
  1383. OffsetReturnRectangle = New Rectangle(r.X + amount, r.Y + amount, r.Width - (amount * 2), r.Height - (amount * 2))
  1384. Return OffsetReturnRectangle
  1385. End Function
  1386.  
  1387. Private OffsetReturnSize As Size
  1388. Protected Function Offset(ByVal s As Size, ByVal amount As Integer) As Size
  1389. OffsetReturnSize = New Size(s.Width + amount, s.Height + amount)
  1390. Return OffsetReturnSize
  1391. End Function
  1392.  
  1393. Private OffsetReturnPoint As Point
  1394. Protected Function Offset(ByVal p As Point, ByVal amount As Integer) As Point
  1395. OffsetReturnPoint = New Point(p.X + amount, p.Y + amount)
  1396. Return OffsetReturnPoint
  1397. End Function
  1398.  
  1399. #End Region
  1400.  
  1401. #Region " Center "
  1402.  
  1403. Private CenterReturn As Point
  1404.  
  1405. Protected Function Center(ByVal p As Rectangle, ByVal c As Rectangle) As Point
  1406. CenterReturn = New Point((p.Width \ 2 - c.Width \ 2) + p.X + c.X, (p.Height \ 2 - c.Height \ 2) + p.Y + c.Y)
  1407. Return CenterReturn
  1408. End Function
  1409. Protected Function Center(ByVal p As Rectangle, ByVal c As Size) As Point
  1410. CenterReturn = New Point((p.Width \ 2 - c.Width \ 2) + p.X, (p.Height \ 2 - c.Height \ 2) + p.Y)
  1411. Return CenterReturn
  1412. End Function
  1413.  
  1414. Protected Function Center(ByVal child As Rectangle) As Point
  1415. Return Center(Width, Height, child.Width, child.Height)
  1416. End Function
  1417. Protected Function Center(ByVal child As Size) As Point
  1418. Return Center(Width, Height, child.Width, child.Height)
  1419. End Function
  1420. Protected Function Center(ByVal childWidth As Integer, ByVal childHeight As Integer) As Point
  1421. Return Center(Width, Height, childWidth, childHeight)
  1422. End Function
  1423.  
  1424. Protected Function Center(ByVal p As Size, ByVal c As Size) As Point
  1425. Return Center(p.Width, p.Height, c.Width, c.Height)
  1426. End Function
  1427.  
  1428. Protected Function Center(ByVal pWidth As Integer, ByVal pHeight As Integer, ByVal cWidth As Integer, ByVal cHeight As Integer) As Point
  1429. CenterReturn = New Point(pWidth \ 2 - cWidth \ 2, pHeight \ 2 - cHeight \ 2)
  1430. Return CenterReturn
  1431. End Function
  1432.  
  1433. #End Region
  1434.  
  1435. #Region " Measure "
  1436.  
  1437. Private MeasureBitmap As Bitmap
  1438. Private MeasureGraphics As Graphics 'TODO: Potential issues during multi-threading.
  1439.  
  1440. Protected Function Measure() As Size
  1441. Return MeasureGraphics.MeasureString(Text, Font, Width).ToSize
  1442. End Function
  1443. Protected Function Measure(ByVal text As String) As Size
  1444. Return MeasureGraphics.MeasureString(text, Font, Width).ToSize
  1445. End Function
  1446.  
  1447. #End Region
  1448.  
  1449.  
  1450. #Region " DrawPixel "
  1451.  
  1452. Private DrawPixelBrush As SolidBrush
  1453.  
  1454. Protected Sub DrawPixel(ByVal c1 As Color, ByVal x As Integer, ByVal y As Integer)
  1455. If _Transparent Then
  1456. B.SetPixel(x, y, c1)
  1457. Else
  1458. DrawPixelBrush = New SolidBrush(c1)
  1459. G.FillRectangle(DrawPixelBrush, x, y, 1, 1)
  1460. End If
  1461. End Sub
  1462.  
  1463. #End Region
  1464.  
  1465. #Region " DrawCorners "
  1466.  
  1467. Private DrawCornersBrush As SolidBrush
  1468.  
  1469. Protected Sub DrawCorners(ByVal c1 As Color, ByVal offset As Integer)
  1470. DrawCorners(c1, 0, 0, Width, Height, offset)
  1471. End Sub
  1472. Protected Sub DrawCorners(ByVal c1 As Color, ByVal r1 As Rectangle, ByVal offset As Integer)
  1473. DrawCorners(c1, r1.X, r1.Y, r1.Width, r1.Height, offset)
  1474. End Sub
  1475. Protected Sub DrawCorners(ByVal c1 As Color, ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer, ByVal offset As Integer)
  1476. DrawCorners(c1, x + offset, y + offset, width - (offset * 2), height - (offset * 2))
  1477. End Sub
  1478.  
  1479. Protected Sub DrawCorners(ByVal c1 As Color)
  1480. DrawCorners(c1, 0, 0, Width, Height)
  1481. End Sub
  1482. Protected Sub DrawCorners(ByVal c1 As Color, ByVal r1 As Rectangle)
  1483. DrawCorners(c1, r1.X, r1.Y, r1.Width, r1.Height)
  1484. End Sub
  1485. Protected Sub DrawCorners(ByVal c1 As Color, ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer)
  1486. If _NoRounding Then Return
  1487.  
  1488. If _Transparent Then
  1489. B.SetPixel(x, y, c1)
  1490. B.SetPixel(x + (width - 1), y, c1)
  1491. B.SetPixel(x, y + (height - 1), c1)
  1492. B.SetPixel(x + (width - 1), y + (height - 1), c1)
  1493. Else
  1494. DrawCornersBrush = New SolidBrush(c1)
  1495. G.FillRectangle(DrawCornersBrush, x, y, 1, 1)
  1496. G.FillRectangle(DrawCornersBrush, x + (width - 1), y, 1, 1)
  1497. G.FillRectangle(DrawCornersBrush, x, y + (height - 1), 1, 1)
  1498. G.FillRectangle(DrawCornersBrush, x + (width - 1), y + (height - 1), 1, 1)
  1499. End If
  1500. End Sub
  1501.  
  1502. #End Region
  1503.  
  1504. #Region " DrawBorders "
  1505.  
  1506. Protected Sub DrawBorders(ByVal p1 As Pen, ByVal offset As Integer)
  1507. DrawBorders(p1, 0, 0, Width, Height, offset)
  1508. End Sub
  1509. Protected Sub DrawBorders(ByVal p1 As Pen, ByVal r As Rectangle, ByVal offset As Integer)
  1510. DrawBorders(p1, r.X, r.Y, r.Width, r.Height, offset)
  1511. End Sub
  1512. 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)
  1513. DrawBorders(p1, x + offset, y + offset, width - (offset * 2), height - (offset * 2))
  1514. End Sub
  1515.  
  1516. Protected Sub DrawBorders(ByVal p1 As Pen)
  1517. DrawBorders(p1, 0, 0, Width, Height)
  1518. End Sub
  1519. Protected Sub DrawBorders(ByVal p1 As Pen, ByVal r As Rectangle)
  1520. DrawBorders(p1, r.X, r.Y, r.Width, r.Height)
  1521. End Sub
  1522. Protected Sub DrawBorders(ByVal p1 As Pen, ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer)
  1523. G.DrawRectangle(p1, x, y, width - 1, height - 1)
  1524. End Sub
  1525.  
  1526. #End Region
  1527.  
  1528. #Region " DrawText "
  1529.  
  1530. Private DrawTextPoint As Point
  1531. Private DrawTextSize As Size
  1532.  
  1533. Protected Sub DrawText(ByVal b1 As Brush, ByVal a As HorizontalAlignment, ByVal x As Integer, ByVal y As Integer)
  1534. DrawText(b1, Text, a, x, y)
  1535. End Sub
  1536. Protected Sub DrawText(ByVal b1 As Brush, ByVal text As String, ByVal a As HorizontalAlignment, ByVal x As Integer, ByVal y As Integer)
  1537. If text.Length = 0 Then Return
  1538.  
  1539. DrawTextSize = Measure(text)
  1540. DrawTextPoint = Center(DrawTextSize)
  1541.  
  1542. Select Case a
  1543. Case HorizontalAlignment.Left
  1544. G.DrawString(text, Font, b1, x, DrawTextPoint.Y + y)
  1545. Case HorizontalAlignment.Center
  1546. G.DrawString(text, Font, b1, DrawTextPoint.X + x, DrawTextPoint.Y + y)
  1547. Case HorizontalAlignment.Right
  1548. G.DrawString(text, Font, b1, Width - DrawTextSize.Width - x, DrawTextPoint.Y + y)
  1549. End Select
  1550. End Sub
  1551.  
  1552. Protected Sub DrawText(ByVal b1 As Brush, ByVal p1 As Point)
  1553. If Text.Length = 0 Then Return
  1554. G.DrawString(Text, Font, b1, p1)
  1555. End Sub
  1556. Protected Sub DrawText(ByVal b1 As Brush, ByVal x As Integer, ByVal y As Integer)
  1557. If Text.Length = 0 Then Return
  1558. G.DrawString(Text, Font, b1, x, y)
  1559. End Sub
  1560.  
  1561. #End Region
  1562.  
  1563. #Region " DrawImage "
  1564.  
  1565. Private DrawImagePoint As Point
  1566.  
  1567. Protected Sub DrawImage(ByVal a As HorizontalAlignment, ByVal x As Integer, ByVal y As Integer)
  1568. DrawImage(_Image, a, x, y)
  1569. End Sub
  1570. Protected Sub DrawImage(ByVal image As Image, ByVal a As HorizontalAlignment, ByVal x As Integer, ByVal y As Integer)
  1571. If image Is Nothing Then Return
  1572. DrawImagePoint = Center(image.Size)
  1573.  
  1574. Select Case a
  1575. Case HorizontalAlignment.Left
  1576. G.DrawImage(image, x, DrawImagePoint.Y + y, image.Width, image.Height)
  1577. Case HorizontalAlignment.Center
  1578. G.DrawImage(image, DrawImagePoint.X + x, DrawImagePoint.Y + y, image.Width, image.Height)
  1579. Case HorizontalAlignment.Right
  1580. G.DrawImage(image, Width - image.Width - x, DrawImagePoint.Y + y, image.Width, image.Height)
  1581. End Select
  1582. End Sub
  1583.  
  1584. Protected Sub DrawImage(ByVal p1 As Point)
  1585. DrawImage(_Image, p1.X, p1.Y)
  1586. End Sub
  1587. Protected Sub DrawImage(ByVal x As Integer, ByVal y As Integer)
  1588. DrawImage(_Image, x, y)
  1589. End Sub
  1590.  
  1591. Protected Sub DrawImage(ByVal image As Image, ByVal p1 As Point)
  1592. DrawImage(image, p1.X, p1.Y)
  1593. End Sub
  1594. Protected Sub DrawImage(ByVal image As Image, ByVal x As Integer, ByVal y As Integer)
  1595. If image Is Nothing Then Return
  1596. G.DrawImage(image, x, y, image.Width, image.Height)
  1597. End Sub
  1598.  
  1599. #End Region
  1600.  
  1601. #Region " DrawGradient "
  1602.  
  1603. Private DrawGradientBrush As LinearGradientBrush
  1604. Private DrawGradientRectangle As Rectangle
  1605.  
  1606. Protected Sub DrawGradient(ByVal blend As ColorBlend, ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer)
  1607. DrawGradientRectangle = New Rectangle(x, y, width, height)
  1608. DrawGradient(blend, DrawGradientRectangle)
  1609. End Sub
  1610. 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)
  1611. DrawGradientRectangle = New Rectangle(x, y, width, height)
  1612. DrawGradient(blend, DrawGradientRectangle, angle)
  1613. End Sub
  1614.  
  1615. Protected Sub DrawGradient(ByVal blend As ColorBlend, ByVal r As Rectangle)
  1616. DrawGradientBrush = New LinearGradientBrush(r, Color.Empty, Color.Empty, 90.0F)
  1617. DrawGradientBrush.InterpolationColors = blend
  1618. G.FillRectangle(DrawGradientBrush, r)
  1619. End Sub
  1620. Protected Sub DrawGradient(ByVal blend As ColorBlend, ByVal r As Rectangle, ByVal angle As Single)
  1621. DrawGradientBrush = New LinearGradientBrush(r, Color.Empty, Color.Empty, angle)
  1622. DrawGradientBrush.InterpolationColors = blend
  1623. G.FillRectangle(DrawGradientBrush, r)
  1624. End Sub
  1625.  
  1626.  
  1627. 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)
  1628. DrawGradientRectangle = New Rectangle(x, y, width, height)
  1629. DrawGradient(c1, c2, DrawGradientRectangle)
  1630. End Sub
  1631. 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)
  1632. DrawGradientRectangle = New Rectangle(x, y, width, height)
  1633. DrawGradient(c1, c2, DrawGradientRectangle, angle)
  1634. End Sub
  1635.  
  1636. Protected Sub DrawGradient(ByVal c1 As Color, ByVal c2 As Color, ByVal r As Rectangle)
  1637. DrawGradientBrush = New LinearGradientBrush(r, c1, c2, 90.0F)
  1638. G.FillRectangle(DrawGradientBrush, r)
  1639. End Sub
  1640. Protected Sub DrawGradient(ByVal c1 As Color, ByVal c2 As Color, ByVal r As Rectangle, ByVal angle As Single)
  1641. DrawGradientBrush = New LinearGradientBrush(r, c1, c2, angle)
  1642. G.FillRectangle(DrawGradientBrush, r)
  1643. End Sub
  1644.  
  1645. #End Region
  1646.  
  1647. #Region " DrawRadial "
  1648.  
  1649. Private DrawRadialPath As GraphicsPath
  1650. Private DrawRadialBrush1 As PathGradientBrush
  1651. Private DrawRadialBrush2 As LinearGradientBrush
  1652. Private DrawRadialRectangle As Rectangle
  1653.  
  1654. Sub DrawRadial(ByVal blend As ColorBlend, ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer)
  1655. DrawRadialRectangle = New Rectangle(x, y, width, height)
  1656. DrawRadial(blend, DrawRadialRectangle, width \ 2, height \ 2)
  1657. End Sub
  1658. Sub DrawRadial(ByVal blend As ColorBlend, ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer, ByVal center As Point)
  1659. DrawRadialRectangle = New Rectangle(x, y, width, height)
  1660. DrawRadial(blend, DrawRadialRectangle, center.X, center.Y)
  1661. End Sub
  1662. Sub DrawRadial(ByVal blend As ColorBlend, ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer, ByVal cx As Integer, ByVal cy As Integer)
  1663. DrawRadialRectangle = New Rectangle(x, y, width, height)
  1664. DrawRadial(blend, DrawRadialRectangle, cx, cy)
  1665. End Sub
  1666.  
  1667. Sub DrawRadial(ByVal blend As ColorBlend, ByVal r As Rectangle)
  1668. DrawRadial(blend, r, r.Width \ 2, r.Height \ 2)
  1669. End Sub
  1670. Sub DrawRadial(ByVal blend As ColorBlend, ByVal r As Rectangle, ByVal center As Point)
  1671. DrawRadial(blend, r, center.X, center.Y)
  1672. End Sub
  1673. Sub DrawRadial(ByVal blend As ColorBlend, ByVal r As Rectangle, ByVal cx As Integer, ByVal cy As Integer)
  1674. DrawRadialPath.Reset()
  1675. DrawRadialPath.AddEllipse(r.X, r.Y, r.Width - 1, r.Height - 1)
  1676.  
  1677. DrawRadialBrush1 = New PathGradientBrush(DrawRadialPath)
  1678. DrawRadialBrush1.CenterPoint = New Point(r.X + cx, r.Y + cy)
  1679. DrawRadialBrush1.InterpolationColors = blend
  1680.  
  1681. If G.SmoothingMode = SmoothingMode.AntiAlias Then
  1682. G.FillEllipse(DrawRadialBrush1, r.X + 1, r.Y + 1, r.Width - 3, r.Height - 3)
  1683. Else
  1684. G.FillEllipse(DrawRadialBrush1, r)
  1685. End If
  1686. End Sub
  1687.  
  1688.  
  1689. Protected Sub DrawRadial(ByVal c1 As Color, ByVal c2 As Color, ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer)
  1690. DrawRadialRectangle = New Rectangle(x, y, width, height)
  1691. DrawRadial(c1, c2, DrawRadialRectangle)
  1692. End Sub
  1693. Protected Sub DrawRadial(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)
  1694. DrawRadialRectangle = New Rectangle(x, y, width, height)
  1695. DrawRadial(c1, c2, DrawRadialRectangle, angle)
  1696. End Sub
  1697.  
  1698. Protected Sub DrawRadial(ByVal c1 As Color, ByVal c2 As Color, ByVal r As Rectangle)
  1699. DrawRadialBrush2 = New LinearGradientBrush(r, c1, c2, 90.0F)
  1700. G.FillEllipse(DrawRadialBrush2, r)
  1701. End Sub
  1702. Protected Sub DrawRadial(ByVal c1 As Color, ByVal c2 As Color, ByVal r As Rectangle, ByVal angle As Single)
  1703. DrawRadialBrush2 = New LinearGradientBrush(r, c1, c2, angle)
  1704. G.FillEllipse(DrawRadialBrush2, r)
  1705. End Sub
  1706.  
  1707. #End Region
  1708.  
  1709. End Class
  1710.  
  1711. Enum MouseState As Byte
  1712. None = 0
  1713. Over = 1
  1714. Down = 2
  1715. Block = 3
  1716. End Enum
  1717.  
  1718. Structure Bloom
  1719.  
  1720. Public _Name As String
  1721. ReadOnly Property Name() As String
  1722. Get
  1723. Return _Name
  1724. End Get
  1725. End Property
  1726.  
  1727. Private _Value As Color
  1728. Property Value() As Color
  1729. Get
  1730. Return _Value
  1731. End Get
  1732. Set(ByVal value As Color)
  1733. _Value = value
  1734. End Set
  1735. End Property
  1736.  
  1737. Sub New(ByVal name As String, ByVal value As Color)
  1738. _Name = name
  1739. _Value = value
  1740. End Sub
  1741. End Structure
  1742. MustInherit Class ThemeContainer151
  1743. Inherits ContainerControl
  1744.  
  1745. Protected G As Graphics
  1746.  
  1747. Sub New()
  1748. SetStyle(DirectCast(139270, ControlStyles), True)
  1749. _ImageSize = Size.Empty
  1750.  
  1751. MeasureBitmap = New Bitmap(1, 1)
  1752. MeasureGraphics = Graphics.FromImage(MeasureBitmap)
  1753.  
  1754. Font = New Font("Verdana", 8S)
  1755.  
  1756. InvalidateCustimization()
  1757. End Sub
  1758.  
  1759. Protected Overrides Sub SetBoundsCore(ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer, ByVal specified As BoundsSpecified)
  1760. If Not _LockWidth = 0 Then width = _LockWidth
  1761. If Not _LockHeight = 0 Then height = _LockHeight
  1762. MyBase.SetBoundsCore(x, y, width, height, specified)
  1763. End Sub
  1764.  
  1765. Private Header As Rectangle
  1766. Protected NotOverridable Overrides Sub OnSizeChanged(ByVal e As EventArgs)
  1767. MyBase.OnSizeChanged(e)
  1768. If _Movable AndAlso Not _ControlMode Then Header = New Rectangle(7, 7, Width - 14, _MoveHeight - 7)
  1769. Invalidate()
  1770. End Sub
  1771.  
  1772. Protected NotOverridable Overrides Sub OnPaint(ByVal e As PaintEventArgs)
  1773. If Width = 0 OrElse Height = 0 Then Return
  1774. G = e.Graphics
  1775. PaintHook()
  1776. End Sub
  1777.  
  1778. Protected NotOverridable Overrides Sub OnHandleCreated(ByVal e As EventArgs)
  1779. InitializeMessages()
  1780. InvalidateCustimization()
  1781. ColorHook()
  1782.  
  1783. _IsParentForm = TypeOf Parent Is Form
  1784. If Not _ControlMode Then Dock = DockStyle.Fill
  1785.  
  1786. If Not _LockWidth = 0 Then Width = _LockWidth
  1787. If Not _LockHeight = 0 Then Height = _LockHeight
  1788. If Not BackColorWait = Nothing Then BackColor = BackColorWait
  1789.  
  1790. If _IsParentForm AndAlso Not _ControlMode Then
  1791. ParentForm.FormBorderStyle = _BorderStyle
  1792. ParentForm.TransparencyKey = _TransparencyKey
  1793. End If
  1794.  
  1795. OnCreation()
  1796. MyBase.OnHandleCreated(e)
  1797. End Sub
  1798.  
  1799. Protected Overridable Sub OnCreation()
  1800. End Sub
  1801.  
  1802. #Region " Sizing and Movement "
  1803.  
  1804. Protected State As MouseState
  1805. Private Sub SetState(ByVal current As MouseState)
  1806. State = current
  1807. Invalidate()
  1808. End Sub
  1809.  
  1810. Protected Overrides Sub OnMouseMove(ByVal e As MouseEventArgs)
  1811. If _Sizable AndAlso Not _ControlMode Then InvalidateMouse()
  1812. MyBase.OnMouseMove(e)
  1813. End Sub
  1814.  
  1815. Protected Overrides Sub OnEnabledChanged(ByVal e As EventArgs)
  1816. If Enabled Then SetState(MouseState.None) Else SetState(MouseState.Block)
  1817. MyBase.OnEnabledChanged(e)
  1818. End Sub
  1819.  
  1820. Protected Overrides Sub OnMouseEnter(ByVal e As EventArgs)
  1821. SetState(MouseState.Over)
  1822. MyBase.OnMouseEnter(e)
  1823. End Sub
  1824.  
  1825. Protected Overrides Sub OnMouseUp(ByVal e As MouseEventArgs)
  1826. SetState(MouseState.Over)
  1827. MyBase.OnMouseUp(e)
  1828. End Sub
  1829.  
  1830. Protected Overrides Sub OnMouseLeave(ByVal e As EventArgs)
  1831. SetState(MouseState.None)
  1832.  
  1833. If _Sizable AndAlso Not _ControlMode AndAlso GetChildAtPoint(PointToClient(MousePosition)) IsNot Nothing Then
  1834. Cursor = Cursors.Default
  1835. Previous = 0
  1836. End If
  1837.  
  1838. MyBase.OnMouseLeave(e)
  1839. End Sub
  1840.  
  1841. Protected Overrides Sub OnMouseDown(ByVal e As MouseEventArgs)
  1842. MyBase.OnMouseDown(e)
  1843.  
  1844. If Not e.Button = Windows.Forms.MouseButtons.Left Then Return
  1845. SetState(MouseState.Down)
  1846.  
  1847. If _IsParentForm AndAlso ParentForm.WindowState = FormWindowState.Maximized OrElse _ControlMode Then Return
  1848.  
  1849. If _Movable AndAlso Header.Contains(e.Location) Then
  1850. Capture = False
  1851. DefWndProc(Messages(0))
  1852. ElseIf _Sizable AndAlso Not Previous = 0 Then
  1853. Capture = False
  1854. DefWndProc(Messages(Previous))
  1855. End If
  1856. End Sub
  1857.  
  1858. Private GetIndexPoint As Point
  1859. Private B1, B2, B3, B4 As Boolean
  1860. Private Function GetIndex() As Integer
  1861. GetIndexPoint = PointToClient(MousePosition)
  1862. B1 = GetIndexPoint.X < 7
  1863. B2 = GetIndexPoint.X > Width - 7
  1864. B3 = GetIndexPoint.Y < 7
  1865. B4 = GetIndexPoint.Y > Height - 7
  1866.  
  1867. If B1 AndAlso B3 Then Return 4
  1868. If B1 AndAlso B4 Then Return 7
  1869. If B2 AndAlso B3 Then Return 5
  1870. If B2 AndAlso B4 Then Return 8
  1871. If B1 Then Return 1
  1872. If B2 Then Return 2
  1873. If B3 Then Return 3
  1874. If B4 Then Return 6
  1875. Return 0
  1876. End Function
  1877.  
  1878. Private Current, Previous As Integer
  1879. Private Sub InvalidateMouse()
  1880. Current = GetIndex()
  1881. If Current = Previous Then Return
  1882.  
  1883. Previous = Current
  1884. Select Case Previous
  1885. Case 0
  1886. Cursor = Cursors.Default
  1887. Case 1, 2
  1888. Cursor = Cursors.SizeWE
  1889. Case 3, 6
  1890. Cursor = Cursors.SizeNS
  1891. Case 4, 8
  1892. Cursor = Cursors.SizeNWSE
  1893. Case 5, 7
  1894. Cursor = Cursors.SizeNESW
  1895. End Select
  1896. End Sub
  1897.  
  1898. Private Messages(8) As Message
  1899. Private Sub InitializeMessages()
  1900. Messages(0) = Message.Create(Parent.Handle, 161, New IntPtr(2), IntPtr.Zero)
  1901. For I As Integer = 1 To 8
  1902. Messages(I) = Message.Create(Parent.Handle, 161, New IntPtr(I + 9), IntPtr.Zero)
  1903. Next
  1904. End Sub
  1905.  
  1906. #End Region
  1907.  
  1908.  
  1909. #Region " Property Overrides "
  1910.  
  1911. Private BackColorWait As Color
  1912. Overrides Property BackColor() As Color
  1913. Get
  1914. Return MyBase.BackColor
  1915. End Get
  1916. Set(ByVal value As Color)
  1917. If IsHandleCreated Then
  1918. If Not _ControlMode Then Parent.BackColor = value
  1919. MyBase.BackColor = value
  1920. Else
  1921. BackColorWait = value
  1922. End If
  1923. End Set
  1924. End Property
  1925.  
  1926. <Browsable(False), EditorBrowsable(EditorBrowsableState.Never), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _
  1927. Overrides Property ForeColor() As Color
  1928. Get
  1929. Return Color.Empty
  1930. End Get
  1931. Set(ByVal value As Color)
  1932. End Set
  1933. End Property
  1934. <Browsable(False), EditorBrowsable(EditorBrowsableState.Never), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _
  1935. Overrides Property BackgroundImage() As Image
  1936. Get
  1937. Return Nothing
  1938. End Get
  1939. Set(ByVal value As Image)
  1940. End Set
  1941. End Property
  1942. <Browsable(False), EditorBrowsable(EditorBrowsableState.Never), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _
  1943. Overrides Property BackgroundImageLayout() As ImageLayout
  1944. Get
  1945. Return ImageLayout.None
  1946. End Get
  1947. Set(ByVal value As ImageLayout)
  1948. End Set
  1949. End Property
  1950.  
  1951. Overrides Property Text() As String
  1952. Get
  1953. Return MyBase.Text
  1954. End Get
  1955. Set(ByVal value As String)
  1956. MyBase.Text = value
  1957. Invalidate()
  1958. End Set
  1959. End Property
  1960.  
  1961. Overrides Property Font() As Font
  1962. Get
  1963. Return MyBase.Font
  1964. End Get
  1965. Set(ByVal value As Font)
  1966. MyBase.Font = value
  1967. Invalidate()
  1968. End Set
  1969. End Property
  1970.  
  1971. #End Region
  1972.  
  1973. #Region " Properties "
  1974.  
  1975. Private _Movable As Boolean = True
  1976. Property Movable() As Boolean
  1977. Get
  1978. Return _Movable
  1979. End Get
  1980. Set(ByVal value As Boolean)
  1981. _Movable = value
  1982. End Set
  1983. End Property
  1984.  
  1985. Private _Sizable As Boolean = True
  1986. Property Sizable() As Boolean
  1987. Get
  1988. Return _Sizable
  1989. End Get
  1990. Set(ByVal value As Boolean)
  1991. _Sizable = value
  1992. End Set
  1993. End Property
  1994.  
  1995. Private _MoveHeight As Integer = 24
  1996. Protected Property MoveHeight() As Integer
  1997. Get
  1998. Return _MoveHeight
  1999. End Get
  2000. Set(ByVal v As Integer)
  2001. If v < 8 Then Return
  2002. Header = New Rectangle(7, 7, Width - 14, v - 7)
  2003. _MoveHeight = v
  2004. Invalidate()
  2005. End Set
  2006. End Property
  2007.  
  2008. Private _ControlMode As Boolean
  2009. Protected Property ControlMode() As Boolean
  2010. Get
  2011. Return _ControlMode
  2012. End Get
  2013. Set(ByVal v As Boolean)
  2014. _ControlMode = v
  2015. End Set
  2016. End Property
  2017.  
  2018. Private _TransparencyKey As Color
  2019. Property TransparencyKey() As Color
  2020. Get
  2021. If _IsParentForm AndAlso Not _ControlMode Then Return ParentForm.TransparencyKey Else Return _TransparencyKey
  2022. End Get
  2023. Set(ByVal value As Color)
  2024. If _IsParentForm AndAlso Not _ControlMode Then ParentForm.TransparencyKey = value
  2025. _TransparencyKey = value
  2026. End Set
  2027. End Property
  2028.  
  2029. Private _BorderStyle As FormBorderStyle
  2030. Property BorderStyle() As FormBorderStyle
  2031. Get
  2032. If _IsParentForm AndAlso Not _ControlMode Then Return ParentForm.FormBorderStyle Else Return _BorderStyle
  2033. End Get
  2034. Set(ByVal value As FormBorderStyle)
  2035. If _IsParentForm AndAlso Not _ControlMode Then ParentForm.FormBorderStyle = value
  2036. _BorderStyle = value
  2037. End Set
  2038. End Property
  2039.  
  2040. Private _NoRounding As Boolean
  2041. Property NoRounding() As Boolean
  2042. Get
  2043. Return _NoRounding
  2044. End Get
  2045. Set(ByVal v As Boolean)
  2046. _NoRounding = v
  2047. Invalidate()
  2048. End Set
  2049. End Property
  2050.  
  2051. Private _Image As Image
  2052. Property Image() As Image
  2053. Get
  2054. Return _Image
  2055. End Get
  2056. Set(ByVal value As Image)
  2057. If value Is Nothing Then
  2058. _ImageSize = Size.Empty
  2059. Else
  2060. _ImageSize = value.Size
  2061. End If
  2062.  
  2063. _Image = value
  2064. Invalidate()
  2065. End Set
  2066. End Property
  2067.  
  2068. Private _ImageSize As Size
  2069. Protected ReadOnly Property ImageSize() As Size
  2070. Get
  2071. Return _ImageSize
  2072. End Get
  2073. End Property
  2074.  
  2075. Private _IsParentForm As Boolean
  2076. Protected ReadOnly Property IsParentForm() As Boolean
  2077. Get
  2078. Return _IsParentForm
  2079. End Get
  2080. End Property
  2081.  
  2082. Private _LockWidth As Integer
  2083. Protected Property LockWidth() As Integer
  2084. Get
  2085. Return _LockWidth
  2086. End Get
  2087. Set(ByVal value As Integer)
  2088. _LockWidth = value
  2089. If Not LockWidth = 0 AndAlso IsHandleCreated Then Width = LockWidth
  2090. End Set
  2091. End Property
  2092.  
  2093. Private _LockHeight As Integer
  2094. Protected Property LockHeight() As Integer
  2095. Get
  2096. Return _LockHeight
  2097. End Get
  2098. Set(ByVal value As Integer)
  2099. _LockHeight = value
  2100. If Not LockHeight = 0 AndAlso IsHandleCreated Then Height = LockHeight
  2101. End Set
  2102. End Property
  2103.  
  2104. Private Items As New Dictionary(Of String, Color)
  2105. <DesignerSerializationVisibility(DesignerSerializationVisibility.Content)> _
  2106. Property Colors() As Bloom()
  2107. Get
  2108. Dim T As New List(Of Bloom)
  2109. Dim E As Dictionary(Of String, Color).Enumerator = Items.GetEnumerator
  2110.  
  2111. While E.MoveNext
  2112. T.Add(New Bloom(E.Current.Key, E.Current.Value))
  2113. End While
  2114.  
  2115. Return T.ToArray
  2116. End Get
  2117. Set(ByVal value As Bloom())
  2118. For Each B As Bloom In value
  2119. If Items.ContainsKey(B.Name) Then Items(B.Name) = B.Value
  2120. Next
  2121.  
  2122. InvalidateCustimization()
  2123. ColorHook()
  2124. Invalidate()
  2125. End Set
  2126. End Property
  2127.  
  2128. Private _Customization As String
  2129. Property Customization() As String
  2130. Get
  2131. Return _Customization
  2132. End Get
  2133. Set(ByVal value As String)
  2134. If value = _Customization Then Return
  2135.  
  2136. Dim Data As Byte()
  2137. Dim Items As Bloom() = Colors
  2138.  
  2139. Try
  2140. Data = Convert.FromBase64String(value)
  2141. For I As Integer = 0 To Items.Length - 1
  2142. Items(I).Value = Color.FromArgb(BitConverter.ToInt32(Data, I * 4))
  2143. Next
  2144. Catch
  2145. Return
  2146. End Try
  2147.  
  2148. _Customization = value
  2149.  
  2150. Colors = Items
  2151. ColorHook()
  2152. Invalidate()
  2153. End Set
  2154. End Property
  2155.  
  2156. #End Region
  2157.  
  2158. #Region " Property Helpers "
  2159.  
  2160. Protected Function GetColor(ByVal name As String) As Color
  2161. Return Items(name)
  2162. End Function
  2163.  
  2164. Protected Sub SetColor(ByVal name As String, ByVal color As Color)
  2165. If Items.ContainsKey(name) Then Items(name) = color Else Items.Add(name, color)
  2166. End Sub
  2167. Protected Sub SetColor(ByVal name As String, ByVal r As Byte, ByVal g As Byte, ByVal b As Byte)
  2168. SetColor(name, Color.FromArgb(r, g, b))
  2169. End Sub
  2170. Protected Sub SetColor(ByVal name As String, ByVal a As Byte, ByVal r As Byte, ByVal g As Byte, ByVal b As Byte)
  2171. SetColor(name, Color.FromArgb(a, r, g, b))
  2172. End Sub
  2173. Protected Sub SetColor(ByVal name As String, ByVal a As Byte, ByVal color As Color)
  2174. SetColor(name, color.FromArgb(a, color))
  2175. End Sub
  2176.  
  2177. Private Sub InvalidateCustimization()
  2178. Dim M As New MemoryStream(Items.Count * 4)
  2179.  
  2180. For Each B As Bloom In Colors
  2181. M.Write(BitConverter.GetBytes(B.Value.ToArgb), 0, 4)
  2182. Next
  2183.  
  2184. M.Close()
  2185. _Customization = Convert.ToBase64String(M.ToArray)
  2186. End Sub
  2187.  
  2188. #End Region
  2189.  
  2190.  
  2191. #Region " User Hooks "
  2192.  
  2193. Protected MustOverride Sub ColorHook()
  2194. Protected MustOverride Sub PaintHook()
  2195.  
  2196. #End Region
  2197.  
  2198.  
  2199. #Region " Center Overloads "
  2200.  
  2201. Private CenterReturn As Point
  2202.  
  2203. Protected Function Center(ByVal r1 As Rectangle, ByVal s1 As Size) As Point
  2204. CenterReturn = New Point((r1.Width \ 2 - s1.Width \ 2) + r1.X, (r1.Height \ 2 - s1.Height \ 2) + r1.Y)
  2205. Return CenterReturn
  2206. End Function
  2207. Protected Function Center(ByVal r1 As Rectangle, ByVal r2 As Rectangle) As Point
  2208. Return Center(r1, r2.Size)
  2209. End Function
  2210.  
  2211. Protected Function Center(ByVal w1 As Integer, ByVal h1 As Integer, ByVal w2 As Integer, ByVal h2 As Integer) As Point
  2212. CenterReturn = New Point(w1 \ 2 - w2 \ 2, h1 \ 2 - h2 \ 2)
  2213. Return CenterReturn
  2214. End Function
  2215.  
  2216. Protected Function Center(ByVal s1 As Size, ByVal s2 As Size) As Point
  2217. Return Center(s1.Width, s1.Height, s2.Width, s2.Height)
  2218. End Function
  2219.  
  2220. Protected Function Center(ByVal r1 As Rectangle) As Point
  2221. Return Center(ClientRectangle.Width, ClientRectangle.Height, r1.Width, r1.Height)
  2222. End Function
  2223. Protected Function Center(ByVal s1 As Size) As Point
  2224. Return Center(Width, Height, s1.Width, s1.Height)
  2225. End Function
  2226. Protected Function Center(ByVal w1 As Integer, ByVal h1 As Integer) As Point
  2227. Return Center(Width, Height, w1, h1)
  2228. End Function
  2229.  
  2230. #End Region
  2231.  
  2232. #Region " Measure Overloads "
  2233.  
  2234. Private MeasureBitmap As Bitmap
  2235. Private MeasureGraphics As Graphics
  2236.  
  2237. Protected Function Measure(ByVal text As String) As Size
  2238. Return MeasureGraphics.MeasureString(text, Font, Width).ToSize
  2239. End Function
  2240. Protected Function Measure() As Size
  2241. Return MeasureGraphics.MeasureString(Text, Font).ToSize
  2242. End Function
  2243.  
  2244. #End Region
  2245.  
  2246. #Region " DrawCorners Overloads "
  2247.  
  2248. 'TODO: Optimize by checking brush color
  2249.  
  2250. Private DrawCornersBrush As SolidBrush
  2251.  
  2252. Protected Sub DrawCorners(ByVal c1 As Color)
  2253. DrawCorners(c1, 0, 0, Width, Height)
  2254. End Sub
  2255. Protected Sub DrawCorners(ByVal c1 As Color, ByVal r1 As Rectangle)
  2256. DrawCorners(c1, r1.X, r1.Y, r1.Width, r1.Height)
  2257. End Sub
  2258. Protected Sub DrawCorners(ByVal c1 As Color, ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer)
  2259. If _NoRounding Then Return
  2260.  
  2261. DrawCornersBrush = New SolidBrush(c1)
  2262. G.FillRectangle(DrawCornersBrush, x, y, 1, 1)
  2263. G.FillRectangle(DrawCornersBrush, x + (width - 1), y, 1, 1)
  2264. G.FillRectangle(DrawCornersBrush, x, y + (height - 1), 1, 1)
  2265. G.FillRectangle(DrawCornersBrush, x + (width - 1), y + (height - 1), 1, 1)
  2266. End Sub
  2267.  
  2268. #End Region
  2269.  
  2270. #Region " DrawBorders Overloads "
  2271.  
  2272. 'TODO: Remove triple overload?
  2273.  
  2274. 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)
  2275. DrawBorders(p1, x + offset, y + offset, width - (offset * 2), height - (offset * 2))
  2276. End Sub
  2277. Protected Sub DrawBorders(ByVal p1 As Pen, ByVal offset As Integer)
  2278. DrawBorders(p1, 0, 0, Width, Height, offset)
  2279. End Sub
  2280. Protected Sub DrawBorders(ByVal p1 As Pen, ByVal r As Rectangle, ByVal offset As Integer)
  2281. DrawBorders(p1, r.X, r.Y, r.Width, r.Height, offset)
  2282. End Sub
  2283.  
  2284. Protected Sub DrawBorders(ByVal p1 As Pen, ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer)
  2285. G.DrawRectangle(p1, x, y, width - 1, height - 1)
  2286. End Sub
  2287. Protected Sub DrawBorders(ByVal p1 As Pen)
  2288. DrawBorders(p1, 0, 0, Width, Height)
  2289. End Sub
  2290. Protected Sub DrawBorders(ByVal p1 As Pen, ByVal r As Rectangle)
  2291. DrawBorders(p1, r.X, r.Y, r.Width, r.Height)
  2292. End Sub
  2293.  
  2294. #End Region
  2295.  
  2296. #Region " DrawText Overloads "
  2297.  
  2298. 'TODO: Remove triple overloads?
  2299.  
  2300. Private DrawTextPoint As Point
  2301. Private DrawTextSize As Size
  2302.  
  2303. Protected Sub DrawText(ByVal b1 As Brush, ByVal a As HorizontalAlignment, ByVal x As Integer, ByVal y As Integer)
  2304. DrawText(b1, Text, a, x, y)
  2305. End Sub
  2306. Protected Sub DrawText(ByVal b1 As Brush, ByVal p1 As Point)
  2307. DrawText(b1, Text, p1.X, p1.Y)
  2308. End Sub
  2309. Protected Sub DrawText(ByVal b1 As Brush, ByVal x As Integer, ByVal y As Integer)
  2310. DrawText(b1, Text, x, y)
  2311. End Sub
  2312.  
  2313. Protected Sub DrawText(ByVal b1 As Brush, ByVal text As String, ByVal a As HorizontalAlignment, ByVal x As Integer, ByVal y As Integer)
  2314. If text.Length = 0 Then Return
  2315. DrawTextSize = Measure(text)
  2316. DrawTextPoint = New Point(Width \ 2 - DrawTextSize.Width \ 2, MoveHeight \ 2 - DrawTextSize.Height \ 2)
  2317.  
  2318. Select Case a
  2319. Case HorizontalAlignment.Left
  2320. DrawText(b1, text, x, DrawTextPoint.Y + y)
  2321. Case HorizontalAlignment.Center
  2322. DrawText(b1, text, DrawTextPoint.X + x, DrawTextPoint.Y + y)
  2323. Case HorizontalAlignment.Right
  2324. DrawText(b1, text, Width - DrawTextSize.Width - x, DrawTextPoint.Y + y)
  2325. End Select
  2326. End Sub
  2327. Protected Sub DrawText(ByVal b1 As Brush, ByVal text As String, ByVal p1 As Point)
  2328. DrawText(b1, text, p1.X, p1.Y)
  2329. End Sub
  2330. Protected Sub DrawText(ByVal b1 As Brush, ByVal text As String, ByVal x As Integer, ByVal y As Integer)
  2331. If text.Length = 0 Then Return
  2332. G.DrawString(text, Font, b1, x, y)
  2333. End Sub
  2334.  
  2335. #End Region
  2336.  
  2337. #Region " DrawImage Overloads "
  2338.  
  2339. 'TODO: Remove triple overloads?
  2340.  
  2341. Private DrawImagePoint As Point
  2342.  
  2343. Protected Sub DrawImage(ByVal a As HorizontalAlignment, ByVal x As Integer, ByVal y As Integer)
  2344. DrawImage(_Image, a, x, y)
  2345. End Sub
  2346. Protected Sub DrawImage(ByVal p1 As Point)
  2347. DrawImage(_Image, p1.X, p1.Y)
  2348. End Sub
  2349. Protected Sub DrawImage(ByVal x As Integer, ByVal y As Integer)
  2350. DrawImage(_Image, x, y)
  2351. End Sub
  2352.  
  2353. Protected Sub DrawImage(ByVal image As Image, ByVal a As HorizontalAlignment, ByVal x As Integer, ByVal y As Integer)
  2354. If image Is Nothing Then Return
  2355. DrawImagePoint = New Point(Width \ 2 - image.Width \ 2, MoveHeight \ 2 - image.Height \ 2)
  2356.  
  2357. Select Case a
  2358. Case HorizontalAlignment.Left
  2359. DrawImage(image, x, DrawImagePoint.Y + y)
  2360. Case HorizontalAlignment.Center
  2361. DrawImage(image, DrawImagePoint.X + x, DrawImagePoint.Y + y)
  2362. Case HorizontalAlignment.Right
  2363. DrawImage(image, Width - image.Width - x, DrawImagePoint.Y + y)
  2364. End Select
  2365. End Sub
  2366. Protected Sub DrawImage(ByVal image As Image, ByVal p1 As Point)
  2367. DrawImage(image, p1.X, p1.Y)
  2368. End Sub
  2369. Protected Sub DrawImage(ByVal image As Image, ByVal x As Integer, ByVal y As Integer)
  2370. If image Is Nothing Then Return
  2371. G.DrawImage(image, x, y, image.Width, image.Height)
  2372. End Sub
  2373.  
  2374. #End Region
  2375.  
  2376. #Region " DrawGradient Overloads "
  2377.  
  2378. 'TODO: Remove triple overload?
  2379.  
  2380. Private DrawGradientBrush As LinearGradientBrush
  2381. Private DrawGradientRectangle As Rectangle
  2382.  
  2383. Protected Sub DrawGradient(ByVal blend As ColorBlend, ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer)
  2384. DrawGradient(blend, x, y, width, height, 90S)
  2385. End Sub
  2386. 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)
  2387. DrawGradient(c1, c2, x, y, width, height, 90S)
  2388. End Sub
  2389.  
  2390. 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)
  2391. DrawGradientRectangle = New Rectangle(x, y, width, height)
  2392. DrawGradient(blend, DrawGradientRectangle, angle)
  2393. End Sub
  2394. 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)
  2395. DrawGradientRectangle = New Rectangle(x, y, width, height)
  2396. DrawGradient(c1, c2, DrawGradientRectangle, angle)
  2397. End Sub
  2398.  
  2399. Protected Sub DrawGradient(ByVal blend As ColorBlend, ByVal r As Rectangle, ByVal angle As Single)
  2400. DrawGradientBrush = New LinearGradientBrush(r, Color.Empty, Color.Empty, angle)
  2401. DrawGradientBrush.InterpolationColors = blend
  2402. G.FillRectangle(DrawGradientBrush, r)
  2403. End Sub
  2404. Protected Sub DrawGradient(ByVal c1 As Color, ByVal c2 As Color, ByVal r As Rectangle, ByVal angle As Single)
  2405. DrawGradientBrush = New LinearGradientBrush(r, c1, c2, angle)
  2406. G.FillRectangle(DrawGradientBrush, r)
  2407. End Sub
  2408.  
  2409. #End Region
  2410.  
  2411. End Class
  2412.  
  2413. MustInherit Class ThemeControl151
  2414. Inherits Control
  2415.  
  2416. Protected G As Graphics, B As Bitmap
  2417.  
  2418. Sub New()
  2419. SetStyle(DirectCast(139270, ControlStyles), True)
  2420.  
  2421. _ImageSize = Size.Empty
  2422.  
  2423. MeasureBitmap = New Bitmap(1, 1)
  2424. MeasureGraphics = Graphics.FromImage(MeasureBitmap)
  2425.  
  2426. Font = New Font("Verdana", 8S)
  2427.  
  2428. InvalidateCustimization()
  2429. End Sub
  2430.  
  2431. Protected Overrides Sub SetBoundsCore(ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer, ByVal specified As BoundsSpecified)
  2432. If Not _LockWidth = 0 Then width = _LockWidth
  2433. If Not _LockHeight = 0 Then height = _LockHeight
  2434. MyBase.SetBoundsCore(x, y, width, height, specified)
  2435. End Sub
  2436.  
  2437. Protected NotOverridable Overrides Sub OnSizeChanged(ByVal e As EventArgs)
  2438. If _Transparent AndAlso Not (Width = 0 OrElse Height = 0) Then
  2439. B = New Bitmap(Width, Height)
  2440. G = Graphics.FromImage(B)
  2441. End If
  2442.  
  2443. Invalidate()
  2444. MyBase.OnSizeChanged(e)
  2445. End Sub
  2446.  
  2447. Protected NotOverridable Overrides Sub OnPaint(ByVal e As PaintEventArgs)
  2448. If Width = 0 OrElse Height = 0 Then Return
  2449.  
  2450. If _Transparent Then
  2451. PaintHook()
  2452. e.Graphics.DrawImage(B, 0, 0)
  2453. Else
  2454. G = e.Graphics
  2455. PaintHook()
  2456. End If
  2457. End Sub
  2458.  
  2459. Protected Overrides Sub OnHandleCreated(ByVal e As EventArgs)
  2460. InvalidateCustimization()
  2461. ColorHook()
  2462.  
  2463. If Not _LockWidth = 0 Then Width = _LockWidth
  2464. If Not _LockHeight = 0 Then Height = _LockHeight
  2465. If Not BackColorWait = Nothing Then BackColor = BackColorWait
  2466.  
  2467. OnCreation()
  2468. MyBase.OnHandleCreated(e)
  2469. End Sub
  2470.  
  2471. Protected Overridable Sub OnCreation()
  2472. End Sub
  2473.  
  2474. #Region " State Handling "
  2475.  
  2476. Protected Overrides Sub OnMouseEnter(ByVal e As EventArgs)
  2477. SetState(MouseState.Over)
  2478. MyBase.OnMouseEnter(e)
  2479. End Sub
  2480.  
  2481. Protected Overrides Sub OnMouseUp(ByVal e As MouseEventArgs)
  2482. SetState(MouseState.Over)
  2483. MyBase.OnMouseUp(e)
  2484. End Sub
  2485.  
  2486. Protected Overrides Sub OnMouseDown(ByVal e As MouseEventArgs)
  2487. If e.Button = Windows.Forms.MouseButtons.Left Then SetState(MouseState.Down)
  2488. MyBase.OnMouseDown(e)
  2489. End Sub
  2490.  
  2491. Protected Overrides Sub OnMouseLeave(ByVal e As EventArgs)
  2492. SetState(MouseState.None)
  2493. MyBase.OnMouseLeave(e)
  2494. End Sub
  2495.  
  2496. Protected Overrides Sub OnEnabledChanged(ByVal e As EventArgs)
  2497. If Enabled Then SetState(MouseState.None) Else SetState(MouseState.Block)
  2498. MyBase.OnEnabledChanged(e)
  2499. End Sub
  2500.  
  2501. Protected State As MouseState
  2502. Private Sub SetState(ByVal current As MouseState)
  2503. State = current
  2504. Invalidate()
  2505. End Sub
  2506.  
  2507. #End Region
  2508.  
  2509.  
  2510. #Region " Property Overrides "
  2511.  
  2512. Private BackColorWait As Color
  2513. Overrides Property BackColor() As Color
  2514. Get
  2515. Return MyBase.BackColor
  2516. End Get
  2517. Set(ByVal value As Color)
  2518. If IsHandleCreated Then
  2519. MyBase.BackColor = value
  2520. Else
  2521. BackColorWait = value
  2522. End If
  2523. End Set
  2524. End Property
  2525.  
  2526. <Browsable(False), EditorBrowsable(EditorBrowsableState.Never), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _
  2527. Overrides Property ForeColor() As Color
  2528. Get
  2529. Return Color.Empty
  2530. End Get
  2531. Set(ByVal value As Color)
  2532. End Set
  2533. End Property
  2534. <Browsable(False), EditorBrowsable(EditorBrowsableState.Never), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _
  2535. Overrides Property BackgroundImage() As Image
  2536. Get
  2537. Return Nothing
  2538. End Get
  2539. Set(ByVal value As Image)
  2540. End Set
  2541. End Property
  2542. <Browsable(False), EditorBrowsable(EditorBrowsableState.Never), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _
  2543. Overrides Property BackgroundImageLayout() As ImageLayout
  2544. Get
  2545. Return ImageLayout.None
  2546. End Get
  2547. Set(ByVal value As ImageLayout)
  2548. End Set
  2549. End Property
  2550.  
  2551. Overrides Property Text() As String
  2552. Get
  2553. Return MyBase.Text
  2554. End Get
  2555. Set(ByVal value As String)
  2556. MyBase.Text = value
  2557. Invalidate()
  2558. End Set
  2559. End Property
  2560.  
  2561. Overrides Property Font() As Font
  2562. Get
  2563. Return MyBase.Font
  2564. End Get
  2565. Set(ByVal value As Font)
  2566. MyBase.Font = value
  2567. Invalidate()
  2568. End Set
  2569. End Property
  2570.  
  2571. #End Region
  2572.  
  2573. #Region " Properties "
  2574.  
  2575. Private _NoRounding As Boolean
  2576. Property NoRounding() As Boolean
  2577. Get
  2578. Return _NoRounding
  2579. End Get
  2580. Set(ByVal v As Boolean)
  2581. _NoRounding = v
  2582. Invalidate()
  2583. End Set
  2584. End Property
  2585.  
  2586. Private _Image As Image
  2587. Property Image() As Image
  2588. Get
  2589. Return _Image
  2590. End Get
  2591. Set(ByVal value As Image)
  2592. If value Is Nothing Then
  2593. _ImageSize = Size.Empty
  2594. Else
  2595. _ImageSize = value.Size
  2596. End If
  2597.  
  2598. _Image = value
  2599. Invalidate()
  2600. End Set
  2601. End Property
  2602.  
  2603. Private _ImageSize As Size
  2604. Protected ReadOnly Property ImageSize() As Size
  2605. Get
  2606. Return _ImageSize
  2607. End Get
  2608. End Property
  2609.  
  2610. Private _LockWidth As Integer
  2611. Protected Property LockWidth() As Integer
  2612. Get
  2613. Return _LockWidth
  2614. End Get
  2615. Set(ByVal value As Integer)
  2616. _LockWidth = value
  2617. If Not LockWidth = 0 AndAlso IsHandleCreated Then Width = LockWidth
  2618. End Set
  2619. End Property
  2620.  
  2621. Private _LockHeight As Integer
  2622. Protected Property LockHeight() As Integer
  2623. Get
  2624. Return _LockHeight
  2625. End Get
  2626. Set(ByVal value As Integer)
  2627. _LockHeight = value
  2628. If Not LockHeight = 0 AndAlso IsHandleCreated Then Height = LockHeight
  2629. End Set
  2630. End Property
  2631.  
  2632. Private _Transparent As Boolean
  2633. Property Transparent() As Boolean
  2634. Get
  2635. Return _Transparent
  2636. End Get
  2637. Set(ByVal value As Boolean)
  2638. If Not value AndAlso Not BackColor.A = 255 Then
  2639. Throw New Exception("Unable to change value to false while a transparent BackColor is in use.")
  2640. End If
  2641.  
  2642. SetStyle(ControlStyles.Opaque, Not value)
  2643. SetStyle(ControlStyles.SupportsTransparentBackColor, value)
  2644.  
  2645. If value Then InvalidateBitmap() Else B = Nothing
  2646.  
  2647. _Transparent = value
  2648. Invalidate()
  2649. End Set
  2650. End Property
  2651.  
  2652. Private Items As New Dictionary(Of String, Color)
  2653. <DesignerSerializationVisibility(DesignerSerializationVisibility.Content)> _
  2654. Property Colors() As Bloom()
  2655. Get
  2656. Dim T As New List(Of Bloom)
  2657. Dim E As Dictionary(Of String, Color).Enumerator = Items.GetEnumerator
  2658.  
  2659. While E.MoveNext
  2660. T.Add(New Bloom(E.Current.Key, E.Current.Value))
  2661. End While
  2662.  
  2663. Return T.ToArray
  2664. End Get
  2665. Set(ByVal value As Bloom())
  2666. For Each B As Bloom In value
  2667. If Items.ContainsKey(B.Name) Then Items(B.Name) = B.Value
  2668. Next
  2669.  
  2670. InvalidateCustimization()
  2671. ColorHook()
  2672. Invalidate()
  2673. End Set
  2674. End Property
  2675.  
  2676. Private _Customization As String
  2677. Property Customization() As String
  2678. Get
  2679. Return _Customization
  2680. End Get
  2681. Set(ByVal value As String)
  2682. If value = _Customization Then Return
  2683.  
  2684. Dim Data As Byte()
  2685. Dim Items As Bloom() = Colors
  2686.  
  2687. Try
  2688. Data = Convert.FromBase64String(value)
  2689. For I As Integer = 0 To Items.Length - 1
  2690. Items(I).Value = Color.FromArgb(BitConverter.ToInt32(Data, I * 4))
  2691. Next
  2692. Catch
  2693. Return
  2694. End Try
  2695.  
  2696. _Customization = value
  2697.  
  2698. Colors = Items
  2699. ColorHook()
  2700. Invalidate()
  2701. End Set
  2702. End Property
  2703.  
  2704. #End Region
  2705.  
  2706. #Region " Property Helpers "
  2707.  
  2708. Private Sub InvalidateBitmap()
  2709. If Width = 0 OrElse Height = 0 Then Return
  2710. B = New Bitmap(Width, Height)
  2711. G = Graphics.FromImage(B)
  2712. End Sub
  2713.  
  2714. Protected Function GetColor(ByVal name As String) As Color
  2715. Return Items(name)
  2716. End Function
  2717.  
  2718. Protected Sub SetColor(ByVal name As String, ByVal color As Color)
  2719. If Items.ContainsKey(name) Then Items(name) = color Else Items.Add(name, color)
  2720. End Sub
  2721. Protected Sub SetColor(ByVal name As String, ByVal r As Byte, ByVal g As Byte, ByVal b As Byte)
  2722. SetColor(name, Color.FromArgb(r, g, b))
  2723. End Sub
  2724. Protected Sub SetColor(ByVal name As String, ByVal a As Byte, ByVal r As Byte, ByVal g As Byte, ByVal b As Byte)
  2725. SetColor(name, Color.FromArgb(a, r, g, b))
  2726. End Sub
  2727. Protected Sub SetColor(ByVal name As String, ByVal a As Byte, ByVal color As Color)
  2728. SetColor(name, color.FromArgb(a, color))
  2729. End Sub
  2730.  
  2731. Private Sub InvalidateCustimization()
  2732. Dim M As New MemoryStream(Items.Count * 4)
  2733.  
  2734. For Each B As Bloom In Colors
  2735. M.Write(BitConverter.GetBytes(B.Value.ToArgb), 0, 4)
  2736. Next
  2737.  
  2738. M.Close()
  2739. _Customization = Convert.ToBase64String(M.ToArray)
  2740. End Sub
  2741.  
  2742. #End Region
  2743.  
  2744.  
  2745. #Region " User Hooks "
  2746.  
  2747. Protected MustOverride Sub ColorHook()
  2748. Protected MustOverride Sub PaintHook()
  2749.  
  2750. #End Region
  2751.  
  2752.  
  2753. #Region " Center Overloads "
  2754.  
  2755. Private CenterReturn As Point
  2756.  
  2757. Protected Function Center(ByVal r1 As Rectangle, ByVal s1 As Size) As Point
  2758. CenterReturn = New Point((r1.Width \ 2 - s1.Width \ 2) + r1.X, (r1.Height \ 2 - s1.Height \ 2) + r1.Y)
  2759. Return CenterReturn
  2760. End Function
  2761. Protected Function Center(ByVal r1 As Rectangle, ByVal r2 As Rectangle) As Point
  2762. Return Center(r1, r2.Size)
  2763. End Function
  2764.  
  2765. Protected Function Center(ByVal w1 As Integer, ByVal h1 As Integer, ByVal w2 As Integer, ByVal h2 As Integer) As Point
  2766. CenterReturn = New Point(w1 \ 2 - w2 \ 2, h1 \ 2 - h2 \ 2)
  2767. Return CenterReturn
  2768. End Function
  2769.  
  2770. Protected Function Center(ByVal s1 As Size, ByVal s2 As Size) As Point
  2771. Return Center(s1.Width, s1.Height, s2.Width, s2.Height)
  2772. End Function
  2773.  
  2774. Protected Function Center(ByVal r1 As Rectangle) As Point
  2775. Return Center(ClientRectangle.Width, ClientRectangle.Height, r1.Width, r1.Height)
  2776. End Function
  2777. Protected Function Center(ByVal s1 As Size) As Point
  2778. Return Center(Width, Height, s1.Width, s1.Height)
  2779. End Function
  2780. Protected Function Center(ByVal w1 As Integer, ByVal h1 As Integer) As Point
  2781. Return Center(Width, Height, w1, h1)
  2782. End Function
  2783.  
  2784. #End Region
  2785.  
  2786. #Region " Measure Overloads "
  2787.  
  2788. Private MeasureBitmap As Bitmap
  2789. Private MeasureGraphics As Graphics
  2790.  
  2791. Protected Function Measure(ByVal text As String) As Size
  2792. Return MeasureGraphics.MeasureString(text, Font, Width).ToSize
  2793. End Function
  2794. Protected Function Measure() As Size
  2795. Return MeasureGraphics.MeasureString(Text, Font, Width).ToSize
  2796. End Function
  2797.  
  2798. #End Region
  2799.  
  2800. #Region " DrawCorners Overloads "
  2801.  
  2802. 'TODO: Optimize by checking brush color
  2803.  
  2804. Private DrawCornersBrush As SolidBrush
  2805.  
  2806. Protected Sub DrawCorners(ByVal c1 As Color)
  2807. DrawCorners(c1, 0, 0, Width, Height)
  2808. End Sub
  2809. Protected Sub DrawCorners(ByVal c1 As Color, ByVal r1 As Rectangle)
  2810. DrawCorners(c1, r1.X, r1.Y, r1.Width, r1.Height)
  2811. End Sub
  2812. Protected Sub DrawCorners(ByVal c1 As Color, ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer)
  2813. If _NoRounding Then Return
  2814.  
  2815. If _Transparent Then
  2816. B.SetPixel(x, y, c1)
  2817. B.SetPixel(x + (width - 1), y, c1)
  2818. B.SetPixel(x, y + (height - 1), c1)
  2819. B.SetPixel(x + (width - 1), y + (height - 1), c1)
  2820. Else
  2821. DrawCornersBrush = New SolidBrush(c1)
  2822. G.FillRectangle(DrawCornersBrush, x, y, 1, 1)
  2823. G.FillRectangle(DrawCornersBrush, x + (width - 1), y, 1, 1)
  2824. G.FillRectangle(DrawCornersBrush, x, y + (height - 1), 1, 1)
  2825. G.FillRectangle(DrawCornersBrush, x + (width - 1), y + (height - 1), 1, 1)
  2826. End If
  2827. End Sub
  2828.  
  2829. #End Region
  2830.  
  2831. #Region " DrawBorders Overloads "
  2832.  
  2833. 'TODO: Remove triple overload?
  2834.  
  2835. 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)
  2836. DrawBorders(p1, x + offset, y + offset, width - (offset * 2), height - (offset * 2))
  2837. End Sub
  2838. Protected Sub DrawBorders(ByVal p1 As Pen, ByVal offset As Integer)
  2839. DrawBorders(p1, 0, 0, Width, Height, offset)
  2840. End Sub
  2841. Protected Sub DrawBorders(ByVal p1 As Pen, ByVal r As Rectangle, ByVal offset As Integer)
  2842. DrawBorders(p1, r.X, r.Y, r.Width, r.Height, offset)
  2843. End Sub
  2844.  
  2845. Protected Sub DrawBorders(ByVal p1 As Pen, ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer)
  2846. G.DrawRectangle(p1, x, y, width - 1, height - 1)
  2847. End Sub
  2848. Protected Sub DrawBorders(ByVal p1 As Pen)
  2849. DrawBorders(p1, 0, 0, Width, Height)
  2850. End Sub
  2851. Protected Sub DrawBorders(ByVal p1 As Pen, ByVal r As Rectangle)
  2852. DrawBorders(p1, r.X, r.Y, r.Width, r.Height)
  2853. End Sub
  2854.  
  2855. #End Region
  2856.  
  2857. #Region " DrawText Overloads "
  2858.  
  2859. 'TODO: Remove triple overloads?
  2860.  
  2861. Private DrawTextPoint As Point
  2862. Private DrawTextSize As Size
  2863.  
  2864. Protected Sub DrawText(ByVal b1 As Brush, ByVal a As HorizontalAlignment, ByVal x As Integer, ByVal y As Integer)
  2865. DrawText(b1, Text, a, x, y)
  2866. End Sub
  2867. Protected Sub DrawText(ByVal b1 As Brush, ByVal p1 As Point)
  2868. DrawText(b1, Text, p1.X, p1.Y)
  2869. End Sub
  2870. Protected Sub DrawText(ByVal b1 As Brush, ByVal x As Integer, ByVal y As Integer)
  2871. DrawText(b1, Text, x, y)
  2872. End Sub
  2873.  
  2874. Protected Sub DrawText(ByVal b1 As Brush, ByVal text As String, ByVal a As HorizontalAlignment, ByVal x As Integer, ByVal y As Integer)
  2875. If text.Length = 0 Then Return
  2876. DrawTextSize = Measure(text)
  2877. DrawTextPoint = Center(DrawTextSize)
  2878.  
  2879. Select Case a
  2880. Case HorizontalAlignment.Left
  2881. DrawText(b1, text, x, DrawTextPoint.Y + y)
  2882. Case HorizontalAlignment.Center
  2883. DrawText(b1, text, DrawTextPoint.X + x, DrawTextPoint.Y + y)
  2884. Case HorizontalAlignment.Right
  2885. DrawText(b1, text, Width - DrawTextSize.Width - x, DrawTextPoint.Y + y)
  2886. End Select
  2887. End Sub
  2888. Protected Sub DrawText(ByVal b1 As Brush, ByVal text As String, ByVal p1 As Point)
  2889. DrawText(b1, text, p1.X, p1.Y)
  2890. End Sub
  2891. Protected Sub DrawText(ByVal b1 As Brush, ByVal text As String, ByVal x As Integer, ByVal y As Integer)
  2892. If text.Length = 0 Then Return
  2893. G.DrawString(text, Font, b1, x, y)
  2894. End Sub
  2895.  
  2896. #End Region
  2897.  
  2898. #Region " DrawImage Overloads "
  2899.  
  2900. 'TODO: Remove triple overloads?
  2901.  
  2902. Private DrawImagePoint As Point
  2903.  
  2904. Protected Sub DrawImage(ByVal a As HorizontalAlignment, ByVal x As Integer, ByVal y As Integer)
  2905. DrawImage(_Image, a, x, y)
  2906. End Sub
  2907. Protected Sub DrawImage(ByVal p1 As Point)
  2908. DrawImage(_Image, p1.X, p1.Y)
  2909. End Sub
  2910. Protected Sub DrawImage(ByVal x As Integer, ByVal y As Integer)
  2911. DrawImage(_Image, x, y)
  2912. End Sub
  2913.  
  2914. Protected Sub DrawImage(ByVal image As Image, ByVal a As HorizontalAlignment, ByVal x As Integer, ByVal y As Integer)
  2915. If image Is Nothing Then Return
  2916. DrawImagePoint = Center(image.Size)
  2917.  
  2918. Select Case a
  2919. Case HorizontalAlignment.Left
  2920. DrawImage(image, x, DrawImagePoint.Y + y)
  2921. Case HorizontalAlignment.Center
  2922. DrawImage(image, DrawImagePoint.X + x, DrawImagePoint.Y + y)
  2923. Case HorizontalAlignment.Right
  2924. DrawImage(image, Width - image.Width - x, DrawImagePoint.Y + y)
  2925. End Select
  2926. End Sub
  2927. Protected Sub DrawImage(ByVal image As Image, ByVal p1 As Point)
  2928. DrawImage(image, p1.X, p1.Y)
  2929. End Sub
  2930. Protected Sub DrawImage(ByVal image As Image, ByVal x As Integer, ByVal y As Integer)
  2931. If image Is Nothing Then Return
  2932. G.DrawImage(image, x, y, image.Width, image.Height)
  2933. End Sub
  2934.  
  2935. #End Region
  2936.  
  2937. #Region " DrawGradient Overloads "
  2938.  
  2939. 'TODO: Remove triple overload?
  2940.  
  2941. Private DrawGradientBrush As LinearGradientBrush
  2942. Private DrawGradientRectangle As Rectangle
  2943.  
  2944. Protected Sub DrawGradient(ByVal blend As ColorBlend, ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer)
  2945. DrawGradient(blend, x, y, width, height, 90S)
  2946. End Sub
  2947. 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)
  2948. DrawGradient(c1, c2, x, y, width, height, 90S)
  2949. End Sub
  2950.  
  2951. 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)
  2952. DrawGradientRectangle = New Rectangle(x, y, width, height)
  2953. DrawGradient(blend, DrawGradientRectangle, angle)
  2954. End Sub
  2955. 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)
  2956. DrawGradientRectangle = New Rectangle(x, y, width, height)
  2957. DrawGradient(c1, c2, DrawGradientRectangle, angle)
  2958. End Sub
  2959.  
  2960. Protected Sub DrawGradient(ByVal blend As ColorBlend, ByVal r As Rectangle, ByVal angle As Single)
  2961. DrawGradientBrush = New LinearGradientBrush(r, Color.Empty, Color.Empty, angle)
  2962. DrawGradientBrush.InterpolationColors = blend
  2963. G.FillRectangle(DrawGradientBrush, r)
  2964. End Sub
  2965. Protected Sub DrawGradient(ByVal c1 As Color, ByVal c2 As Color, ByVal r As Rectangle, ByVal angle As Single)
  2966. DrawGradientBrush = New LinearGradientBrush(r, c1, c2, angle)
  2967. G.FillRectangle(DrawGradientBrush, r)
  2968. End Sub
  2969.  
  2970. #End Region
  2971. End Class
  2972.  
Advertisement
Add Comment
Please, Sign In to add comment