Advertisement
iToxic

Advantium Theme

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