a7m3dalbalawi

ThemeBase 1.5.4

Jan 9th, 2016
682
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 67.95 KB | None | 0 0
  1. #Region "ThemeBase"
  2. Imports System, System.IO, System.Collections.Generic
  3. Imports System.Drawing, System.Drawing.Drawing2D
  4. Imports System.ComponentModel, System.Windows.Forms
  5. Imports System.Runtime.InteropServices
  6. Imports System.Drawing.Imaging
  7. MustInherit Class ThemeContainer154
  8.     Inherits ContainerControl
  9.  
  10. #Region " Initialization "
  11.  
  12.     Protected G As Graphics, B As Bitmap
  13.  
  14.     Sub New()
  15.         SetStyle(DirectCast(139270, ControlStyles), True)
  16.  
  17.         _ImageSize = Size.Empty
  18.         Font = New Font("Verdana", 8S)
  19.  
  20.         MeasureBitmap = New Bitmap(1, 1)
  21.         MeasureGraphics = Graphics.FromImage(MeasureBitmap)
  22.  
  23.         DrawRadialPath = New GraphicsPath
  24.  
  25.         InvalidateCustimization()
  26.     End Sub
  27.  
  28.     Protected NotOverridable Overrides Sub OnHandleCreated(ByVal e As EventArgs)
  29.         If DoneCreation Then InitializeMessages()
  30.  
  31.         InvalidateCustimization()
  32.         ColorHook()
  33.  
  34.         If Not _LockWidth = 0 Then Width = _LockWidth
  35.         If Not _LockHeight = 0 Then Height = _LockHeight
  36.         If Not _ControlMode Then MyBase.Dock = DockStyle.Fill
  37.  
  38.         Transparent = _Transparent
  39.         If _Transparent AndAlso _BackColor Then BackColor = Color.Transparent
  40.  
  41.         MyBase.OnHandleCreated(e)
  42.     End Sub
  43.  
  44.     Private DoneCreation As Boolean
  45.     Protected NotOverridable Overrides Sub OnParentChanged(ByVal e As EventArgs)
  46.         MyBase.OnParentChanged(e)
  47.  
  48.         If Parent Is Nothing Then Return
  49.         _IsParentForm = TypeOf Parent Is Form
  50.  
  51.         If Not _ControlMode Then
  52.             InitializeMessages()
  53.  
  54.             If _IsParentForm Then
  55.                 ParentForm.FormBorderStyle = _BorderStyle
  56.                 ParentForm.TransparencyKey = _TransparencyKey
  57.  
  58.                 If Not DesignMode Then
  59.                     AddHandler ParentForm.Shown, AddressOf FormShown
  60.                 End If
  61.             End If
  62.  
  63.             Parent.BackColor = BackColor
  64.         End If
  65.  
  66.         OnCreation()
  67.         DoneCreation = True
  68.         InvalidateTimer()
  69.     End Sub
  70.  
  71. #End Region
  72.  
  73.     Private Sub DoAnimation(ByVal i As Boolean)
  74.         OnAnimation()
  75.         If i Then Invalidate()
  76.     End Sub
  77.  
  78.     Protected NotOverridable Overrides Sub OnPaint(ByVal e As PaintEventArgs)
  79.         If Width = 0 OrElse Height = 0 Then Return
  80.  
  81.         If _Transparent AndAlso _ControlMode Then
  82.             PaintHook()
  83.             e.Graphics.DrawImage(B, 0, 0)
  84.         Else
  85.             G = e.Graphics
  86.             PaintHook()
  87.         End If
  88.     End Sub
  89.  
  90.     Protected Overrides Sub OnHandleDestroyed(ByVal e As EventArgs)
  91.         RemoveAnimationCallback(AddressOf DoAnimation)
  92.         MyBase.OnHandleDestroyed(e)
  93.     End Sub
  94.  
  95.     Private HasShown As Boolean
  96.     Private Sub FormShown(ByVal sender As Object, ByVal e As EventArgs)
  97.         If _ControlMode OrElse HasShown Then Return
  98.  
  99.         If _StartPosition = FormStartPosition.CenterParent OrElse _StartPosition = FormStartPosition.CenterScreen Then
  100.             Dim SB As Rectangle = Screen.PrimaryScreen.Bounds
  101.             Dim CB As Rectangle = ParentForm.Bounds
  102.             ParentForm.Location = New Point(SB.Width \ 2 - CB.Width \ 2, SB.Height \ 2 - CB.Width \ 2)
  103.         End If
  104.  
  105.         HasShown = True
  106.     End Sub
  107.  
  108.  
  109. #Region " Size Handling "
  110.  
  111.     Private Frame As Rectangle
  112.     Protected NotOverridable Overrides Sub OnSizeChanged(ByVal e As EventArgs)
  113.         If _Movable AndAlso Not _ControlMode Then
  114.             Frame = New Rectangle(7, 7, Width - 14, _Header - 7)
  115.         End If
  116.  
  117.         InvalidateBitmap()
  118.         Invalidate()
  119.  
  120.         MyBase.OnSizeChanged(e)
  121.     End Sub
  122.  
  123.     Protected Overrides Sub SetBoundsCore(ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer, ByVal specified As BoundsSpecified)
  124.         If Not _LockWidth = 0 Then width = _LockWidth
  125.         If Not _LockHeight = 0 Then height = _LockHeight
  126.         MyBase.SetBoundsCore(x, y, width, height, specified)
  127.     End Sub
  128.  
  129. #End Region
  130.  
  131. #Region " State Handling "
  132.  
  133.     Protected State As MouseState
  134.     Private Sub SetState(ByVal current As MouseState)
  135.         State = current
  136.         Invalidate()
  137.     End Sub
  138.  
  139.     Protected Overrides Sub OnMouseMove(ByVal e As MouseEventArgs)
  140.         If Not (_IsParentForm AndAlso ParentForm.WindowState = FormWindowState.Maximized) Then
  141.             If _Sizable AndAlso Not _ControlMode Then InvalidateMouse()
  142.         End If
  143.  
  144.         MyBase.OnMouseMove(e)
  145.     End Sub
  146.  
  147.     Protected Overrides Sub OnEnabledChanged(ByVal e As EventArgs)
  148.         If Enabled Then SetState(MouseState.None) Else SetState(MouseState.Block)
  149.         MyBase.OnEnabledChanged(e)
  150.     End Sub
  151.  
  152.     Protected Overrides Sub OnMouseEnter(ByVal e As EventArgs)
  153.         SetState(MouseState.Over)
  154.         MyBase.OnMouseEnter(e)
  155.     End Sub
  156.  
  157.     Protected Overrides Sub OnMouseUp(ByVal e As MouseEventArgs)
  158.         SetState(MouseState.Over)
  159.         MyBase.OnMouseUp(e)
  160.     End Sub
  161.  
  162.     Protected Overrides Sub OnMouseLeave(ByVal e As EventArgs)
  163.         SetState(MouseState.None)
  164.  
  165.         If GetChildAtPoint(PointToClient(MousePosition)) IsNot Nothing Then
  166.             If _Sizable AndAlso Not _ControlMode Then
  167.                 Cursor = Cursors.Default
  168.                 Previous = 0
  169.             End If
  170.         End If
  171.  
  172.         MyBase.OnMouseLeave(e)
  173.     End Sub
  174.  
  175.     Protected Overrides Sub OnMouseDown(ByVal e As MouseEventArgs)
  176.         If e.Button = Windows.Forms.MouseButtons.Left Then SetState(MouseState.Down)
  177.  
  178.         If Not (_IsParentForm AndAlso ParentForm.WindowState = FormWindowState.Maximized OrElse _ControlMode) Then
  179.             If _Movable AndAlso Frame.Contains(e.Location) Then
  180.                 Capture = False
  181.                 WM_LMBUTTONDOWN = True
  182.                 DefWndProc(Messages(0))
  183.             ElseIf _Sizable AndAlso Not Previous = 0 Then
  184.                 Capture = False
  185.                 WM_LMBUTTONDOWN = True
  186.                 DefWndProc(Messages(Previous))
  187.             End If
  188.         End If
  189.  
  190.         MyBase.OnMouseDown(e)
  191.     End Sub
  192.  
  193.     Private WM_LMBUTTONDOWN As Boolean
  194.     Protected Overrides Sub WndProc(ByRef m As Message)
  195.         MyBase.WndProc(m)
  196.  
  197.         If WM_LMBUTTONDOWN AndAlso m.Msg = 513 Then
  198.             WM_LMBUTTONDOWN = False
  199.  
  200.             SetState(MouseState.Over)
  201.             If Not _SmartBounds Then Return
  202.  
  203.             If IsParentMdi Then
  204.                 CorrectBounds(New Rectangle(Point.Empty, Parent.Parent.Size))
  205.             Else
  206.                 CorrectBounds(Screen.FromControl(Parent).WorkingArea)
  207.             End If
  208.         End If
  209.     End Sub
  210.  
  211.     Private GetIndexPoint As Point
  212.     Private B1, B2, B3, B4 As Boolean
  213.     Private Function GetIndex() As Integer
  214.         GetIndexPoint = PointToClient(MousePosition)
  215.         B1 = GetIndexPoint.X < 7
  216.         B2 = GetIndexPoint.X > Width - 7
  217.         B3 = GetIndexPoint.Y < 7
  218.         B4 = GetIndexPoint.Y > Height - 7
  219.  
  220.         If B1 AndAlso B3 Then Return 4
  221.         If B1 AndAlso B4 Then Return 7
  222.         If B2 AndAlso B3 Then Return 5
  223.         If B2 AndAlso B4 Then Return 8
  224.         If B1 Then Return 1
  225.         If B2 Then Return 2
  226.         If B3 Then Return 3
  227.         If B4 Then Return 6
  228.         Return 0
  229.     End Function
  230.  
  231.     Private Current, Previous As Integer
  232.     Private Sub InvalidateMouse()
  233.         Current = GetIndex()
  234.         If Current = Previous Then Return
  235.  
  236.         Previous = Current
  237.         Select Case Previous
  238.             Case 0
  239.                 Cursor = Cursors.Default
  240.             Case 1, 2
  241.                 Cursor = Cursors.SizeWE
  242.             Case 3, 6
  243.                 Cursor = Cursors.SizeNS
  244.             Case 4, 8
  245.                 Cursor = Cursors.SizeNWSE
  246.             Case 5, 7
  247.                 Cursor = Cursors.SizeNESW
  248.         End Select
  249.     End Sub
  250.  
  251.     Private Messages(8) As Message
  252.     Private Sub InitializeMessages()
  253.         Messages(0) = Message.Create(Parent.Handle, 161, New IntPtr(2), IntPtr.Zero)
  254.         For I As Integer = 1 To 8
  255.             Messages(I) = Message.Create(Parent.Handle, 161, New IntPtr(I + 9), IntPtr.Zero)
  256.         Next
  257.     End Sub
  258.  
  259.     Private Sub CorrectBounds(ByVal bounds As Rectangle)
  260.         If Parent.Width > bounds.Width Then Parent.Width = bounds.Width
  261.         If Parent.Height > bounds.Height Then Parent.Height = bounds.Height
  262.  
  263.         Dim X As Integer = Parent.Location.X
  264.         Dim Y As Integer = Parent.Location.Y
  265.  
  266.         If X < bounds.X Then X = bounds.X
  267.         If Y < bounds.Y Then Y = bounds.Y
  268.  
  269.         Dim Width As Integer = bounds.X + bounds.Width
  270.         Dim Height As Integer = bounds.Y + bounds.Height
  271.  
  272.         If X + Parent.Width > Width Then X = Width - Parent.Width
  273.         If Y + Parent.Height > Height Then Y = Height - Parent.Height
  274.  
  275.         Parent.Location = New Point(X, Y)
  276.     End Sub
  277.  
  278. #End Region
  279.  
  280.  
  281. #Region " Base Properties "
  282.  
  283.     Overrides Property Dock As DockStyle
  284.         Get
  285.             Return MyBase.Dock
  286.         End Get
  287.         Set(ByVal value As DockStyle)
  288.             If Not _ControlMode Then Return
  289.             MyBase.Dock = value
  290.         End Set
  291.     End Property
  292.  
  293.     Private _BackColor As Boolean
  294.     <Category("Misc")> _
  295.     Overrides Property BackColor() As Color
  296.         Get
  297.             Return MyBase.BackColor
  298.         End Get
  299.         Set(ByVal value As Color)
  300.             If value = MyBase.BackColor Then Return
  301.  
  302.             If Not IsHandleCreated AndAlso _ControlMode AndAlso value = Color.Transparent Then
  303.                 _BackColor = True
  304.                 Return
  305.             End If
  306.  
  307.             MyBase.BackColor = value
  308.             If Parent IsNot Nothing Then
  309.                 If Not _ControlMode Then Parent.BackColor = value
  310.                 ColorHook()
  311.             End If
  312.         End Set
  313.     End Property
  314.  
  315.     Overrides Property MinimumSize As Size
  316.         Get
  317.             Return MyBase.MinimumSize
  318.         End Get
  319.         Set(ByVal value As Size)
  320.             MyBase.MinimumSize = value
  321.             If Parent IsNot Nothing Then Parent.MinimumSize = value
  322.         End Set
  323.     End Property
  324.  
  325.     Overrides Property MaximumSize As Size
  326.         Get
  327.             Return MyBase.MaximumSize
  328.         End Get
  329.         Set(ByVal value As Size)
  330.             MyBase.MaximumSize = value
  331.             If Parent IsNot Nothing Then Parent.MaximumSize = value
  332.         End Set
  333.     End Property
  334.  
  335.     Overrides Property Text() As String
  336.         Get
  337.             Return MyBase.Text
  338.         End Get
  339.         Set(ByVal value As String)
  340.             MyBase.Text = value
  341.             Invalidate()
  342.         End Set
  343.     End Property
  344.  
  345.     Overrides Property Font() As Font
  346.         Get
  347.             Return MyBase.Font
  348.         End Get
  349.         Set(ByVal value As Font)
  350.             MyBase.Font = value
  351.             Invalidate()
  352.         End Set
  353.     End Property
  354.  
  355.     <Browsable(False), EditorBrowsable(EditorBrowsableState.Never), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _
  356.     Overrides Property ForeColor() As Color
  357.         Get
  358.             Return Color.Empty
  359.         End Get
  360.         Set(ByVal value As Color)
  361.         End Set
  362.     End Property
  363.     <Browsable(False), EditorBrowsable(EditorBrowsableState.Never), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _
  364.     Overrides Property BackgroundImage() As Image
  365.         Get
  366.             Return Nothing
  367.         End Get
  368.         Set(ByVal value As Image)
  369.         End Set
  370.     End Property
  371.     <Browsable(False), EditorBrowsable(EditorBrowsableState.Never), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _
  372.     Overrides Property BackgroundImageLayout() As ImageLayout
  373.         Get
  374.             Return ImageLayout.None
  375.         End Get
  376.         Set(ByVal value As ImageLayout)
  377.         End Set
  378.     End Property
  379.  
  380. #End Region
  381.  
  382. #Region " Public Properties "
  383.  
  384.     Private _SmartBounds As Boolean = True
  385.     Property SmartBounds() As Boolean
  386.         Get
  387.             Return _SmartBounds
  388.         End Get
  389.         Set(ByVal value As Boolean)
  390.             _SmartBounds = value
  391.         End Set
  392.     End Property
  393.  
  394.     Private _Movable As Boolean = True
  395.     Property Movable() As Boolean
  396.         Get
  397.             Return _Movable
  398.         End Get
  399.         Set(ByVal value As Boolean)
  400.             _Movable = value
  401.         End Set
  402.     End Property
  403.  
  404.     Private _Sizable As Boolean = True
  405.     Property Sizable() As Boolean
  406.         Get
  407.             Return _Sizable
  408.         End Get
  409.         Set(ByVal value As Boolean)
  410.             _Sizable = value
  411.         End Set
  412.     End Property
  413.  
  414.     Private _TransparencyKey As Color
  415.     Property TransparencyKey() As Color
  416.         Get
  417.             If _IsParentForm AndAlso Not _ControlMode Then Return ParentForm.TransparencyKey Else Return _TransparencyKey
  418.         End Get
  419.         Set(ByVal value As Color)
  420.             If value = _TransparencyKey Then Return
  421.             _TransparencyKey = value
  422.  
  423.             If _IsParentForm AndAlso Not _ControlMode Then
  424.                 ParentForm.TransparencyKey = value
  425.                 ColorHook()
  426.             End If
  427.         End Set
  428.     End Property
  429.  
  430.     Private _BorderStyle As FormBorderStyle
  431.     Property BorderStyle() As FormBorderStyle
  432.         Get
  433.             If _IsParentForm AndAlso Not _ControlMode Then Return ParentForm.FormBorderStyle Else Return _BorderStyle
  434.         End Get
  435.         Set(ByVal value As FormBorderStyle)
  436.             _BorderStyle = value
  437.  
  438.             If _IsParentForm AndAlso Not _ControlMode Then
  439.                 ParentForm.FormBorderStyle = value
  440.  
  441.                 If Not value = FormBorderStyle.None Then
  442.                     Movable = False
  443.                     Sizable = False
  444.                 End If
  445.             End If
  446.         End Set
  447.     End Property
  448.  
  449.     Private _StartPosition As FormStartPosition
  450.     Property StartPosition As FormStartPosition
  451.         Get
  452.             If _IsParentForm AndAlso Not _ControlMode Then Return ParentForm.StartPosition Else Return _StartPosition
  453.         End Get
  454.         Set(ByVal value As FormStartPosition)
  455.             _StartPosition = value
  456.  
  457.             If _IsParentForm AndAlso Not _ControlMode Then
  458.                 ParentForm.StartPosition = value
  459.             End If
  460.         End Set
  461.     End Property
  462.  
  463.     Private _NoRounding As Boolean
  464.     Property NoRounding() As Boolean
  465.         Get
  466.             Return _NoRounding
  467.         End Get
  468.         Set(ByVal v As Boolean)
  469.             _NoRounding = v
  470.             Invalidate()
  471.         End Set
  472.     End Property
  473.  
  474.     Private _Image As Image
  475.     Property Image() As Image
  476.         Get
  477.             Return _Image
  478.         End Get
  479.         Set(ByVal value As Image)
  480.             If value Is Nothing Then _ImageSize = Size.Empty Else _ImageSize = value.Size
  481.  
  482.             _Image = value
  483.             Invalidate()
  484.         End Set
  485.     End Property
  486.  
  487.     Private Items As New Dictionary(Of String, Color)
  488.     Property Colors() As Bloom()
  489.         Get
  490.             Dim T As New List(Of Bloom)
  491.             Dim E As Dictionary(Of String, Color).Enumerator = Items.GetEnumerator
  492.  
  493.             While E.MoveNext
  494.                 T.Add(New Bloom(E.Current.Key, E.Current.Value))
  495.             End While
  496.  
  497.             Return T.ToArray
  498.         End Get
  499.         Set(ByVal value As Bloom())
  500.             For Each B As Bloom In value
  501.                 If Items.ContainsKey(B.Name) Then Items(B.Name) = B.Value
  502.             Next
  503.  
  504.             InvalidateCustimization()
  505.             ColorHook()
  506.             Invalidate()
  507.         End Set
  508.     End Property
  509.  
  510.     Private _Customization As String
  511.     Property Customization() As String
  512.         Get
  513.             Return _Customization
  514.         End Get
  515.         Set(ByVal value As String)
  516.             If value = _Customization Then Return
  517.  
  518.             Dim Data As Byte()
  519.             Dim Items As Bloom() = Colors
  520.  
  521.             Try
  522.                 Data = Convert.FromBase64String(value)
  523.                 For I As Integer = 0 To Items.Length - 1
  524.                     Items(I).Value = Color.FromArgb(BitConverter.ToInt32(Data, I * 4))
  525.                 Next
  526.             Catch
  527.                 Return
  528.             End Try
  529.  
  530.             _Customization = value
  531.  
  532.             Colors = Items
  533.             ColorHook()
  534.             Invalidate()
  535.         End Set
  536.     End Property
  537.  
  538.     Private _Transparent As Boolean
  539.     Property Transparent() As Boolean
  540.         Get
  541.             Return _Transparent
  542.         End Get
  543.         Set(ByVal value As Boolean)
  544.             _Transparent = value
  545.             If Not (IsHandleCreated OrElse _ControlMode) Then Return
  546.  
  547.             If Not value AndAlso Not BackColor.A = 255 Then
  548.                 Throw New Exception("Unable to change value to false while a transparent BackColor is in use.")
  549.             End If
  550.  
  551.             SetStyle(ControlStyles.Opaque, Not value)
  552.             SetStyle(ControlStyles.SupportsTransparentBackColor, value)
  553.  
  554.             InvalidateBitmap()
  555.             Invalidate()
  556.         End Set
  557.     End Property
  558.  
  559. #End Region
  560.  
  561. #Region " Private Properties "
  562.  
  563.     Private _ImageSize As Size
  564.     Protected ReadOnly Property ImageSize() As Size
  565.         Get
  566.             Return _ImageSize
  567.         End Get
  568.     End Property
  569.  
  570.     Private _IsParentForm As Boolean
  571.     Protected ReadOnly Property IsParentForm As Boolean
  572.         Get
  573.             Return _IsParentForm
  574.         End Get
  575.     End Property
  576.  
  577.     Protected ReadOnly Property IsParentMdi As Boolean
  578.         Get
  579.             If Parent Is Nothing Then Return False
  580.             Return Parent.Parent IsNot Nothing
  581.         End Get
  582.     End Property
  583.  
  584.     Private _LockWidth As Integer
  585.     Protected Property LockWidth() As Integer
  586.         Get
  587.             Return _LockWidth
  588.         End Get
  589.         Set(ByVal value As Integer)
  590.             _LockWidth = value
  591.             If Not LockWidth = 0 AndAlso IsHandleCreated Then Width = LockWidth
  592.         End Set
  593.     End Property
  594.  
  595.     Private _LockHeight As Integer
  596.     Protected Property LockHeight() As Integer
  597.         Get
  598.             Return _LockHeight
  599.         End Get
  600.         Set(ByVal value As Integer)
  601.             _LockHeight = value
  602.             If Not LockHeight = 0 AndAlso IsHandleCreated Then Height = LockHeight
  603.         End Set
  604.     End Property
  605.  
  606.     Private _Header As Integer = 24
  607.     Protected Property Header() As Integer
  608.         Get
  609.             Return _Header
  610.         End Get
  611.         Set(ByVal v As Integer)
  612.             _Header = v
  613.  
  614.             If Not _ControlMode Then
  615.                 Frame = New Rectangle(7, 7, Width - 14, v - 7)
  616.                 Invalidate()
  617.             End If
  618.         End Set
  619.     End Property
  620.  
  621.     Private _ControlMode As Boolean
  622.     Protected Property ControlMode() As Boolean
  623.         Get
  624.             Return _ControlMode
  625.         End Get
  626.         Set(ByVal v As Boolean)
  627.             _ControlMode = v
  628.  
  629.             Transparent = _Transparent
  630.             If _Transparent AndAlso _BackColor Then BackColor = Color.Transparent
  631.  
  632.             InvalidateBitmap()
  633.             Invalidate()
  634.         End Set
  635.     End Property
  636.  
  637.     Private _IsAnimated As Boolean
  638.     Protected Property IsAnimated() As Boolean
  639.         Get
  640.             Return _IsAnimated
  641.         End Get
  642.         Set(ByVal value As Boolean)
  643.             _IsAnimated = value
  644.             InvalidateTimer()
  645.         End Set
  646.     End Property
  647.  
  648. #End Region
  649.  
  650.  
  651. #Region " Property Helpers "
  652.  
  653.     Protected Function GetPen(ByVal name As String) As Pen
  654.         Return New Pen(Items(name))
  655.     End Function
  656.     Protected Function GetPen(ByVal name As String, ByVal width As Single) As Pen
  657.         Return New Pen(Items(name), width)
  658.     End Function
  659.  
  660.     Protected Function GetBrush(ByVal name As String) As SolidBrush
  661.         Return New SolidBrush(Items(name))
  662.     End Function
  663.  
  664.     Protected Function GetColor(ByVal name As String) As Color
  665.         Return Items(name)
  666.     End Function
  667.  
  668.     Protected Sub SetColor(ByVal name As String, ByVal value As Color)
  669.         If Items.ContainsKey(name) Then Items(name) = value Else Items.Add(name, value)
  670.     End Sub
  671.     Protected Sub SetColor(ByVal name As String, ByVal r As Byte, ByVal g As Byte, ByVal b As Byte)
  672.         SetColor(name, Color.FromArgb(r, g, b))
  673.     End Sub
  674.     Protected Sub SetColor(ByVal name As String, ByVal a As Byte, ByVal r As Byte, ByVal g As Byte, ByVal b As Byte)
  675.         SetColor(name, Color.FromArgb(a, r, g, b))
  676.     End Sub
  677.     Protected Sub SetColor(ByVal name As String, ByVal a As Byte, ByVal value As Color)
  678.         SetColor(name, Color.FromArgb(a, value))
  679.     End Sub
  680.  
  681.     Private Sub InvalidateBitmap()
  682.         If _Transparent AndAlso _ControlMode Then
  683.             If Width = 0 OrElse Height = 0 Then Return
  684.             B = New Bitmap(Width, Height, PixelFormat.Format32bppPArgb)
  685.             G = Graphics.FromImage(B)
  686.         Else
  687.             G = Nothing
  688.             B = Nothing
  689.         End If
  690.     End Sub
  691.  
  692.     Private Sub InvalidateCustimization()
  693.         Dim M As New MemoryStream(Items.Count * 4)
  694.  
  695.         For Each B As Bloom In Colors
  696.             M.Write(BitConverter.GetBytes(B.Value.ToArgb), 0, 4)
  697.         Next
  698.  
  699.         M.Close()
  700.         _Customization = Convert.ToBase64String(M.ToArray)
  701.     End Sub
  702.  
  703.     Private Sub InvalidateTimer()
  704.         If DesignMode OrElse Not DoneCreation Then Return
  705.  
  706.         If _IsAnimated Then
  707.             AddAnimationCallback(AddressOf DoAnimation)
  708.         Else
  709.             RemoveAnimationCallback(AddressOf DoAnimation)
  710.         End If
  711.     End Sub
  712.  
  713. #End Region
  714.  
  715.  
  716. #Region " User Hooks "
  717.  
  718.     Protected MustOverride Sub ColorHook()
  719.     Protected MustOverride Sub PaintHook()
  720.  
  721.     Protected Overridable Sub OnCreation()
  722.     End Sub
  723.  
  724.     Protected Overridable Sub OnAnimation()
  725.     End Sub
  726.  
  727. #End Region
  728.  
  729.  
  730. #Region " Offset "
  731.  
  732.     Private OffsetReturnRectangle As Rectangle
  733.     Protected Function Offset(ByVal r As Rectangle, ByVal amount As Integer) As Rectangle
  734.         OffsetReturnRectangle = New Rectangle(r.X + amount, r.Y + amount, r.Width - (amount * 2), r.Height - (amount * 2))
  735.         Return OffsetReturnRectangle
  736.     End Function
  737.  
  738.     Private OffsetReturnSize As Size
  739.     Protected Function Offset(ByVal s As Size, ByVal amount As Integer) As Size
  740.         OffsetReturnSize = New Size(s.Width + amount, s.Height + amount)
  741.         Return OffsetReturnSize
  742.     End Function
  743.  
  744.     Private OffsetReturnPoint As Point
  745.     Protected Function Offset(ByVal p As Point, ByVal amount As Integer) As Point
  746.         OffsetReturnPoint = New Point(p.X + amount, p.Y + amount)
  747.         Return OffsetReturnPoint
  748.     End Function
  749.  
  750. #End Region
  751.  
  752. #Region " Center "
  753.  
  754.     Private CenterReturn As Point
  755.  
  756.     Protected Function Center(ByVal p As Rectangle, ByVal c As Rectangle) As Point
  757.         CenterReturn = New Point((p.Width \ 2 - c.Width \ 2) + p.X + c.X, (p.Height \ 2 - c.Height \ 2) + p.Y + c.Y)
  758.         Return CenterReturn
  759.     End Function
  760.     Protected Function Center(ByVal p As Rectangle, ByVal c As Size) As Point
  761.         CenterReturn = New Point((p.Width \ 2 - c.Width \ 2) + p.X, (p.Height \ 2 - c.Height \ 2) + p.Y)
  762.         Return CenterReturn
  763.     End Function
  764.  
  765.     Protected Function Center(ByVal child As Rectangle) As Point
  766.         Return Center(Width, Height, child.Width, child.Height)
  767.     End Function
  768.     Protected Function Center(ByVal child As Size) As Point
  769.         Return Center(Width, Height, child.Width, child.Height)
  770.     End Function
  771.     Protected Function Center(ByVal childWidth As Integer, ByVal childHeight As Integer) As Point
  772.         Return Center(Width, Height, childWidth, childHeight)
  773.     End Function
  774.  
  775.     Protected Function Center(ByVal p As Size, ByVal c As Size) As Point
  776.         Return Center(p.Width, p.Height, c.Width, c.Height)
  777.     End Function
  778.  
  779.     Protected Function Center(ByVal pWidth As Integer, ByVal pHeight As Integer, ByVal cWidth As Integer, ByVal cHeight As Integer) As Point
  780.         CenterReturn = New Point(pWidth \ 2 - cWidth \ 2, pHeight \ 2 - cHeight \ 2)
  781.         Return CenterReturn
  782.     End Function
  783.  
  784. #End Region
  785.  
  786. #Region " Measure "
  787.  
  788.     Private MeasureBitmap As Bitmap
  789.     Private MeasureGraphics As Graphics
  790.  
  791.     Protected Function Measure() As Size
  792.         SyncLock MeasureGraphics
  793.             Return MeasureGraphics.MeasureString(Text, Font, Width).ToSize
  794.         End SyncLock
  795.     End Function
  796.     Protected Function Measure(ByVal text As String) As Size
  797.         SyncLock MeasureGraphics
  798.             Return MeasureGraphics.MeasureString(text, Font, Width).ToSize
  799.         End SyncLock
  800.     End Function
  801.  
  802. #End Region
  803.  
  804.  
  805. #Region " DrawPixel "
  806.  
  807.     Private DrawPixelBrush As SolidBrush
  808.  
  809.     Protected Sub DrawPixel(ByVal c1 As Color, ByVal x As Integer, ByVal y As Integer)
  810.         If _Transparent Then
  811.             B.SetPixel(x, y, c1)
  812.         Else
  813.             DrawPixelBrush = New SolidBrush(c1)
  814.             G.FillRectangle(DrawPixelBrush, x, y, 1, 1)
  815.         End If
  816.     End Sub
  817.  
  818. #End Region
  819.  
  820. #Region " DrawCorners "
  821.  
  822.     Private DrawCornersBrush As SolidBrush
  823.  
  824.     Protected Sub DrawCorners(ByVal c1 As Color, ByVal offset As Integer)
  825.         DrawCorners(c1, 0, 0, Width, Height, offset)
  826.     End Sub
  827.     Protected Sub DrawCorners(ByVal c1 As Color, ByVal r1 As Rectangle, ByVal offset As Integer)
  828.         DrawCorners(c1, r1.X, r1.Y, r1.Width, r1.Height, offset)
  829.     End Sub
  830.     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)
  831.         DrawCorners(c1, x + offset, y + offset, width - (offset * 2), height - (offset * 2))
  832.     End Sub
  833.  
  834.     Protected Sub DrawCorners(ByVal c1 As Color)
  835.         DrawCorners(c1, 0, 0, Width, Height)
  836.     End Sub
  837.     Protected Sub DrawCorners(ByVal c1 As Color, ByVal r1 As Rectangle)
  838.         DrawCorners(c1, r1.X, r1.Y, r1.Width, r1.Height)
  839.     End Sub
  840.     Protected Sub DrawCorners(ByVal c1 As Color, ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer)
  841.         If _NoRounding Then Return
  842.  
  843.         If _Transparent Then
  844.             B.SetPixel(x, y, c1)
  845.             B.SetPixel(x + (width - 1), y, c1)
  846.             B.SetPixel(x, y + (height - 1), c1)
  847.             B.SetPixel(x + (width - 1), y + (height - 1), c1)
  848.         Else
  849.             DrawCornersBrush = New SolidBrush(c1)
  850.             G.FillRectangle(DrawCornersBrush, x, y, 1, 1)
  851.             G.FillRectangle(DrawCornersBrush, x + (width - 1), y, 1, 1)
  852.             G.FillRectangle(DrawCornersBrush, x, y + (height - 1), 1, 1)
  853.             G.FillRectangle(DrawCornersBrush, x + (width - 1), y + (height - 1), 1, 1)
  854.         End If
  855.     End Sub
  856.  
  857. #End Region
  858.  
  859. #Region " DrawBorders "
  860.  
  861.     Protected Sub DrawBorders(ByVal p1 As Pen, ByVal offset As Integer)
  862.         DrawBorders(p1, 0, 0, Width, Height, offset)
  863.     End Sub
  864.     Protected Sub DrawBorders(ByVal p1 As Pen, ByVal r As Rectangle, ByVal offset As Integer)
  865.         DrawBorders(p1, r.X, r.Y, r.Width, r.Height, offset)
  866.     End Sub
  867.     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)
  868.         DrawBorders(p1, x + offset, y + offset, width - (offset * 2), height - (offset * 2))
  869.     End Sub
  870.  
  871.     Protected Sub DrawBorders(ByVal p1 As Pen)
  872.         DrawBorders(p1, 0, 0, Width, Height)
  873.     End Sub
  874.     Protected Sub DrawBorders(ByVal p1 As Pen, ByVal r As Rectangle)
  875.         DrawBorders(p1, r.X, r.Y, r.Width, r.Height)
  876.     End Sub
  877.     Protected Sub DrawBorders(ByVal p1 As Pen, ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer)
  878.         G.DrawRectangle(p1, x, y, width - 1, height - 1)
  879.     End Sub
  880.  
  881. #End Region
  882.  
  883. #Region " DrawText "
  884.  
  885.     Private DrawTextPoint As Point
  886.     Private DrawTextSize As Size
  887.  
  888.     Protected Sub DrawText(ByVal b1 As Brush, ByVal a As HorizontalAlignment, ByVal x As Integer, ByVal y As Integer)
  889.         DrawText(b1, Text, a, x, y)
  890.     End Sub
  891.     Protected Sub DrawText(ByVal b1 As Brush, ByVal text As String, ByVal a As HorizontalAlignment, ByVal x As Integer, ByVal y As Integer)
  892.         If text.Length = 0 Then Return
  893.  
  894.         DrawTextSize = Measure(text)
  895.         DrawTextPoint = New Point(Width \ 2 - DrawTextSize.Width \ 2, Header \ 2 - DrawTextSize.Height \ 2)
  896.  
  897.         Select Case a
  898.             Case HorizontalAlignment.Left
  899.                 G.DrawString(text, Font, b1, x, DrawTextPoint.Y + y)
  900.             Case HorizontalAlignment.Center
  901.                 G.DrawString(text, Font, b1, DrawTextPoint.X + x, DrawTextPoint.Y + y)
  902.             Case HorizontalAlignment.Right
  903.                 G.DrawString(text, Font, b1, Width - DrawTextSize.Width - x, DrawTextPoint.Y + y)
  904.         End Select
  905.     End Sub
  906.  
  907.     Protected Sub DrawText(ByVal b1 As Brush, ByVal p1 As Point)
  908.         If Text.Length = 0 Then Return
  909.         G.DrawString(Text, Font, b1, p1)
  910.     End Sub
  911.     Protected Sub DrawText(ByVal b1 As Brush, ByVal x As Integer, ByVal y As Integer)
  912.         If Text.Length = 0 Then Return
  913.         G.DrawString(Text, Font, b1, x, y)
  914.     End Sub
  915.  
  916. #End Region
  917.  
  918. #Region " DrawImage "
  919.  
  920.     Private DrawImagePoint As Point
  921.  
  922.     Protected Sub DrawImage(ByVal a As HorizontalAlignment, ByVal x As Integer, ByVal y As Integer)
  923.         DrawImage(_Image, a, x, y)
  924.     End Sub
  925.     Protected Sub DrawImage(ByVal image As Image, ByVal a As HorizontalAlignment, ByVal x As Integer, ByVal y As Integer)
  926.         If image Is Nothing Then Return
  927.         DrawImagePoint = New Point(Width \ 2 - image.Width \ 2, Header \ 2 - image.Height \ 2)
  928.  
  929.         Select Case a
  930.             Case HorizontalAlignment.Left
  931.                 G.DrawImage(image, x, DrawImagePoint.Y + y, image.Width, image.Height)
  932.             Case HorizontalAlignment.Center
  933.                 G.DrawImage(image, DrawImagePoint.X + x, DrawImagePoint.Y + y, image.Width, image.Height)
  934.             Case HorizontalAlignment.Right
  935.                 G.DrawImage(image, Width - image.Width - x, DrawImagePoint.Y + y, image.Width, image.Height)
  936.         End Select
  937.     End Sub
  938.  
  939.     Protected Sub DrawImage(ByVal p1 As Point)
  940.         DrawImage(_Image, p1.X, p1.Y)
  941.     End Sub
  942.     Protected Sub DrawImage(ByVal x As Integer, ByVal y As Integer)
  943.         DrawImage(_Image, x, y)
  944.     End Sub
  945.  
  946.     Protected Sub DrawImage(ByVal image As Image, ByVal p1 As Point)
  947.         DrawImage(image, p1.X, p1.Y)
  948.     End Sub
  949.     Protected Sub DrawImage(ByVal image As Image, ByVal x As Integer, ByVal y As Integer)
  950.         If image Is Nothing Then Return
  951.         G.DrawImage(image, x, y, image.Width, image.Height)
  952.     End Sub
  953.  
  954. #End Region
  955.  
  956. #Region " DrawGradient "
  957.  
  958.     Private DrawGradientBrush As LinearGradientBrush
  959.     Private DrawGradientRectangle As Rectangle
  960.  
  961.     Protected Sub DrawGradient(ByVal blend As ColorBlend, ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer)
  962.         DrawGradientRectangle = New Rectangle(x, y, width, height)
  963.         DrawGradient(blend, DrawGradientRectangle)
  964.     End Sub
  965.     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)
  966.         DrawGradientRectangle = New Rectangle(x, y, width, height)
  967.         DrawGradient(blend, DrawGradientRectangle, angle)
  968.     End Sub
  969.  
  970.     Protected Sub DrawGradient(ByVal blend As ColorBlend, ByVal r As Rectangle)
  971.         DrawGradientBrush = New LinearGradientBrush(r, Color.Empty, Color.Empty, 90.0F)
  972.         DrawGradientBrush.InterpolationColors = blend
  973.         G.FillRectangle(DrawGradientBrush, r)
  974.     End Sub
  975.     Protected Sub DrawGradient(ByVal blend As ColorBlend, ByVal r As Rectangle, ByVal angle As Single)
  976.         DrawGradientBrush = New LinearGradientBrush(r, Color.Empty, Color.Empty, angle)
  977.         DrawGradientBrush.InterpolationColors = blend
  978.         G.FillRectangle(DrawGradientBrush, r)
  979.     End Sub
  980.  
  981.  
  982.     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)
  983.         DrawGradientRectangle = New Rectangle(x, y, width, height)
  984.         DrawGradient(c1, c2, DrawGradientRectangle)
  985.     End Sub
  986.     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)
  987.         DrawGradientRectangle = New Rectangle(x, y, width, height)
  988.         DrawGradient(c1, c2, DrawGradientRectangle, angle)
  989.     End Sub
  990.  
  991.     Protected Sub DrawGradient(ByVal c1 As Color, ByVal c2 As Color, ByVal r As Rectangle)
  992.         DrawGradientBrush = New LinearGradientBrush(r, c1, c2, 90.0F)
  993.         G.FillRectangle(DrawGradientBrush, r)
  994.     End Sub
  995.     Protected Sub DrawGradient(ByVal c1 As Color, ByVal c2 As Color, ByVal r As Rectangle, ByVal angle As Single)
  996.         DrawGradientBrush = New LinearGradientBrush(r, c1, c2, angle)
  997.         G.FillRectangle(DrawGradientBrush, r)
  998.     End Sub
  999.  
  1000. #End Region
  1001.  
  1002. #Region " DrawRadial "
  1003.  
  1004.     Private DrawRadialPath As GraphicsPath
  1005.     Private DrawRadialBrush1 As PathGradientBrush
  1006.     Private DrawRadialBrush2 As LinearGradientBrush
  1007.     Private DrawRadialRectangle As Rectangle
  1008.  
  1009.     Sub DrawRadial(ByVal blend As ColorBlend, ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer)
  1010.         DrawRadialRectangle = New Rectangle(x, y, width, height)
  1011.         DrawRadial(blend, DrawRadialRectangle, width \ 2, height \ 2)
  1012.     End Sub
  1013.     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)
  1014.         DrawRadialRectangle = New Rectangle(x, y, width, height)
  1015.         DrawRadial(blend, DrawRadialRectangle, center.X, center.Y)
  1016.     End Sub
  1017.     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)
  1018.         DrawRadialRectangle = New Rectangle(x, y, width, height)
  1019.         DrawRadial(blend, DrawRadialRectangle, cx, cy)
  1020.     End Sub
  1021.  
  1022.     Sub DrawRadial(ByVal blend As ColorBlend, ByVal r As Rectangle)
  1023.         DrawRadial(blend, r, r.Width \ 2, r.Height \ 2)
  1024.     End Sub
  1025.     Sub DrawRadial(ByVal blend As ColorBlend, ByVal r As Rectangle, ByVal center As Point)
  1026.         DrawRadial(blend, r, center.X, center.Y)
  1027.     End Sub
  1028.     Sub DrawRadial(ByVal blend As ColorBlend, ByVal r As Rectangle, ByVal cx As Integer, ByVal cy As Integer)
  1029.         DrawRadialPath.Reset()
  1030.         DrawRadialPath.AddEllipse(r.X, r.Y, r.Width - 1, r.Height - 1)
  1031.  
  1032.         DrawRadialBrush1 = New PathGradientBrush(DrawRadialPath)
  1033.         DrawRadialBrush1.CenterPoint = New Point(r.X + cx, r.Y + cy)
  1034.         DrawRadialBrush1.InterpolationColors = blend
  1035.  
  1036.         If G.SmoothingMode = SmoothingMode.AntiAlias Then
  1037.             G.FillEllipse(DrawRadialBrush1, r.X + 1, r.Y + 1, r.Width - 3, r.Height - 3)
  1038.         Else
  1039.             G.FillEllipse(DrawRadialBrush1, r)
  1040.         End If
  1041.     End Sub
  1042.  
  1043.  
  1044.     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)
  1045.         DrawRadialRectangle = New Rectangle(x, y, width, height)
  1046.         DrawRadial(c1, c2, DrawGradientRectangle)
  1047.     End Sub
  1048.     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)
  1049.         DrawRadialRectangle = New Rectangle(x, y, width, height)
  1050.         DrawRadial(c1, c2, DrawGradientRectangle, angle)
  1051.     End Sub
  1052.  
  1053.     Protected Sub DrawRadial(ByVal c1 As Color, ByVal c2 As Color, ByVal r As Rectangle)
  1054.         DrawRadialBrush2 = New LinearGradientBrush(r, c1, c2, 90.0F)
  1055.         G.FillRectangle(DrawGradientBrush, r)
  1056.     End Sub
  1057.     Protected Sub DrawRadial(ByVal c1 As Color, ByVal c2 As Color, ByVal r As Rectangle, ByVal angle As Single)
  1058.         DrawRadialBrush2 = New LinearGradientBrush(r, c1, c2, angle)
  1059.         G.FillEllipse(DrawGradientBrush, r)
  1060.     End Sub
  1061.  
  1062. #End Region
  1063.  
  1064. #Region " CreateRound "
  1065.  
  1066.     Private CreateRoundPath As GraphicsPath
  1067.     Private CreateRoundRectangle As Rectangle
  1068.  
  1069.     Function CreateRound(ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer, ByVal slope As Integer) As GraphicsPath
  1070.         CreateRoundRectangle = New Rectangle(x, y, width, height)
  1071.         Return CreateRound(CreateRoundRectangle, slope)
  1072.     End Function
  1073.  
  1074.     Function CreateRound(ByVal r As Rectangle, ByVal slope As Integer) As GraphicsPath
  1075.         CreateRoundPath = New GraphicsPath(FillMode.Winding)
  1076.         CreateRoundPath.AddArc(r.X, r.Y, slope, slope, 180.0F, 90.0F)
  1077.         CreateRoundPath.AddArc(r.Right - slope, r.Y, slope, slope, 270.0F, 90.0F)
  1078.         CreateRoundPath.AddArc(r.Right - slope, r.Bottom - slope, slope, slope, 0.0F, 90.0F)
  1079.         CreateRoundPath.AddArc(r.X, r.Bottom - slope, slope, slope, 90.0F, 90.0F)
  1080.         CreateRoundPath.CloseFigure()
  1081.         Return CreateRoundPath
  1082.     End Function
  1083.  
  1084. #End Region
  1085.  
  1086. End Class
  1087.  
  1088. MustInherit Class ThemeControl154
  1089.     Inherits Control
  1090.  
  1091.  
  1092. #Region " Initialization "
  1093.  
  1094.     Protected G As Graphics, B As Bitmap
  1095.  
  1096.     Sub New()
  1097.         SetStyle(DirectCast(139270, ControlStyles), True)
  1098.  
  1099.         _ImageSize = Size.Empty
  1100.         Font = New Font("Verdana", 8S)
  1101.  
  1102.         MeasureBitmap = New Bitmap(1, 1)
  1103.         MeasureGraphics = Graphics.FromImage(MeasureBitmap)
  1104.  
  1105.         DrawRadialPath = New GraphicsPath
  1106.  
  1107.         InvalidateCustimization()
  1108.         InvalidateCustimization()
  1109.     End Sub
  1110.  
  1111.     Protected NotOverridable Overrides Sub OnHandleCreated(ByVal e As EventArgs)
  1112.         InvalidateCustimization()
  1113.         ColorHook()
  1114.  
  1115.         If Not _LockWidth = 0 Then Width = _LockWidth
  1116.         If Not _LockHeight = 0 Then Height = _LockHeight
  1117.  
  1118.         Transparent = _Transparent
  1119.         If _Transparent AndAlso _BackColor Then BackColor = Color.Transparent
  1120.  
  1121.         MyBase.OnHandleCreated(e)
  1122.     End Sub
  1123.  
  1124.     Private DoneCreation As Boolean
  1125.     Protected NotOverridable Overrides Sub OnParentChanged(ByVal e As EventArgs)
  1126.         If Parent IsNot Nothing Then
  1127.             OnCreation()
  1128.             DoneCreation = True
  1129.             InvalidateTimer()
  1130.         End If
  1131.  
  1132.         MyBase.OnParentChanged(e)
  1133.     End Sub
  1134.  
  1135. #End Region
  1136.  
  1137.     Private Sub DoAnimation(ByVal i As Boolean)
  1138.         OnAnimation()
  1139.         If i Then Invalidate()
  1140.     End Sub
  1141.  
  1142.     Protected NotOverridable Overrides Sub OnPaint(ByVal e As PaintEventArgs)
  1143.         If Width = 0 OrElse Height = 0 Then Return
  1144.  
  1145.         If _Transparent Then
  1146.             PaintHook()
  1147.             e.Graphics.DrawImage(B, 0, 0)
  1148.         Else
  1149.             G = e.Graphics
  1150.             PaintHook()
  1151.         End If
  1152.     End Sub
  1153.  
  1154.     Protected Overrides Sub OnHandleDestroyed(ByVal e As EventArgs)
  1155.         RemoveAnimationCallback(AddressOf DoAnimation)
  1156.         MyBase.OnHandleDestroyed(e)
  1157.     End Sub
  1158.  
  1159. #Region " Size Handling "
  1160.  
  1161.     Protected NotOverridable Overrides Sub OnSizeChanged(ByVal e As EventArgs)
  1162.         If _Transparent Then
  1163.             InvalidateBitmap()
  1164.         End If
  1165.  
  1166.         Invalidate()
  1167.         MyBase.OnSizeChanged(e)
  1168.     End Sub
  1169.  
  1170.     Protected Overrides Sub SetBoundsCore(ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer, ByVal specified As BoundsSpecified)
  1171.         If Not _LockWidth = 0 Then width = _LockWidth
  1172.         If Not _LockHeight = 0 Then height = _LockHeight
  1173.         MyBase.SetBoundsCore(x, y, width, height, specified)
  1174.     End Sub
  1175.  
  1176. #End Region
  1177.  
  1178. #Region " State Handling "
  1179.  
  1180.     Private InPosition As Boolean
  1181.     Protected Overrides Sub OnMouseEnter(ByVal e As EventArgs)
  1182.         InPosition = True
  1183.         SetState(MouseState.Over)
  1184.         MyBase.OnMouseEnter(e)
  1185.     End Sub
  1186.  
  1187.     Protected Overrides Sub OnMouseUp(ByVal e As MouseEventArgs)
  1188.         If InPosition Then SetState(MouseState.Over)
  1189.         MyBase.OnMouseUp(e)
  1190.     End Sub
  1191.  
  1192.     Protected Overrides Sub OnMouseDown(ByVal e As MouseEventArgs)
  1193.         If e.Button = Windows.Forms.MouseButtons.Left Then SetState(MouseState.Down)
  1194.         MyBase.OnMouseDown(e)
  1195.     End Sub
  1196.  
  1197.     Protected Overrides Sub OnMouseLeave(ByVal e As EventArgs)
  1198.         InPosition = False
  1199.         SetState(MouseState.None)
  1200.         MyBase.OnMouseLeave(e)
  1201.     End Sub
  1202.  
  1203.     Protected Overrides Sub OnEnabledChanged(ByVal e As EventArgs)
  1204.         If Enabled Then SetState(MouseState.None) Else SetState(MouseState.Block)
  1205.         MyBase.OnEnabledChanged(e)
  1206.     End Sub
  1207.  
  1208.     Protected State As MouseState
  1209.     Private Sub SetState(ByVal current As MouseState)
  1210.         State = current
  1211.         Invalidate()
  1212.     End Sub
  1213.  
  1214. #End Region
  1215.  
  1216.  
  1217. #Region " Base Properties "
  1218.  
  1219.     <Browsable(False), EditorBrowsable(EditorBrowsableState.Never), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _
  1220.     Overrides Property ForeColor() As Color
  1221.         Get
  1222.             Return Color.Empty
  1223.         End Get
  1224.         Set(ByVal value As Color)
  1225.         End Set
  1226.     End Property
  1227.     <Browsable(False), EditorBrowsable(EditorBrowsableState.Never), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _
  1228.     Overrides Property BackgroundImage() As Image
  1229.         Get
  1230.             Return Nothing
  1231.         End Get
  1232.         Set(ByVal value As Image)
  1233.         End Set
  1234.     End Property
  1235.     <Browsable(False), EditorBrowsable(EditorBrowsableState.Never), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _
  1236.     Overrides Property BackgroundImageLayout() As ImageLayout
  1237.         Get
  1238.             Return ImageLayout.None
  1239.         End Get
  1240.         Set(ByVal value As ImageLayout)
  1241.         End Set
  1242.     End Property
  1243.  
  1244.     Overrides Property Text() As String
  1245.         Get
  1246.             Return MyBase.Text
  1247.         End Get
  1248.         Set(ByVal value As String)
  1249.             MyBase.Text = value
  1250.             Invalidate()
  1251.         End Set
  1252.     End Property
  1253.     Overrides Property Font() As Font
  1254.         Get
  1255.             Return MyBase.Font
  1256.         End Get
  1257.         Set(ByVal value As Font)
  1258.             MyBase.Font = value
  1259.             Invalidate()
  1260.         End Set
  1261.     End Property
  1262.  
  1263.     Private _BackColor As Boolean
  1264.     <Category("Misc")> _
  1265.     Overrides Property BackColor() As Color
  1266.         Get
  1267.             Return MyBase.BackColor
  1268.         End Get
  1269.         Set(ByVal value As Color)
  1270.             If Not IsHandleCreated AndAlso value = Color.Transparent Then
  1271.                 _BackColor = True
  1272.                 Return
  1273.             End If
  1274.  
  1275.             MyBase.BackColor = value
  1276.             If Parent IsNot Nothing Then ColorHook()
  1277.         End Set
  1278.     End Property
  1279.  
  1280. #End Region
  1281.  
  1282. #Region " Public Properties "
  1283.  
  1284.     Private _NoRounding As Boolean
  1285.     Property NoRounding() As Boolean
  1286.         Get
  1287.             Return _NoRounding
  1288.         End Get
  1289.         Set(ByVal v As Boolean)
  1290.             _NoRounding = v
  1291.             Invalidate()
  1292.         End Set
  1293.     End Property
  1294.  
  1295.     Private _Image As Image
  1296.     Property Image() As Image
  1297.         Get
  1298.             Return _Image
  1299.         End Get
  1300.         Set(ByVal value As Image)
  1301.             If value Is Nothing Then
  1302.                 _ImageSize = Size.Empty
  1303.             Else
  1304.                 _ImageSize = value.Size
  1305.             End If
  1306.  
  1307.             _Image = value
  1308.             Invalidate()
  1309.         End Set
  1310.     End Property
  1311.  
  1312.     Private _Transparent As Boolean
  1313.     Property Transparent() As Boolean
  1314.         Get
  1315.             Return _Transparent
  1316.         End Get
  1317.         Set(ByVal value As Boolean)
  1318.             _Transparent = value
  1319.             If Not IsHandleCreated Then Return
  1320.  
  1321.             If Not value AndAlso Not BackColor.A = 255 Then
  1322.                 Throw New Exception("Unable to change value to false while a transparent BackColor is in use.")
  1323.             End If
  1324.  
  1325.             SetStyle(ControlStyles.Opaque, Not value)
  1326.             SetStyle(ControlStyles.SupportsTransparentBackColor, value)
  1327.  
  1328.             If value Then InvalidateBitmap() Else B = Nothing
  1329.             Invalidate()
  1330.         End Set
  1331.     End Property
  1332.  
  1333.     Private Items As New Dictionary(Of String, Color)
  1334.     Property Colors() As Bloom()
  1335.         Get
  1336.             Dim T As New List(Of Bloom)
  1337.             Dim E As Dictionary(Of String, Color).Enumerator = Items.GetEnumerator
  1338.  
  1339.             While E.MoveNext
  1340.                 T.Add(New Bloom(E.Current.Key, E.Current.Value))
  1341.             End While
  1342.  
  1343.             Return T.ToArray
  1344.         End Get
  1345.         Set(ByVal value As Bloom())
  1346.             For Each B As Bloom In value
  1347.                 If Items.ContainsKey(B.Name) Then Items(B.Name) = B.Value
  1348.             Next
  1349.  
  1350.             InvalidateCustimization()
  1351.             ColorHook()
  1352.             Invalidate()
  1353.         End Set
  1354.     End Property
  1355.  
  1356.     Private _Customization As String
  1357.     Property Customization() As String
  1358.         Get
  1359.             Return _Customization
  1360.         End Get
  1361.         Set(ByVal value As String)
  1362.             If value = _Customization Then Return
  1363.  
  1364.             Dim Data As Byte()
  1365.             Dim Items As Bloom() = Colors
  1366.  
  1367.             Try
  1368.                 Data = Convert.FromBase64String(value)
  1369.                 For I As Integer = 0 To Items.Length - 1
  1370.                     Items(I).Value = Color.FromArgb(BitConverter.ToInt32(Data, I * 4))
  1371.                 Next
  1372.             Catch
  1373.                 Return
  1374.             End Try
  1375.  
  1376.             _Customization = value
  1377.  
  1378.             Colors = Items
  1379.             ColorHook()
  1380.             Invalidate()
  1381.         End Set
  1382.     End Property
  1383.  
  1384. #End Region
  1385.  
  1386. #Region " Private Properties "
  1387.  
  1388.     Private _ImageSize As Size
  1389.     Protected ReadOnly Property ImageSize() As Size
  1390.         Get
  1391.             Return _ImageSize
  1392.         End Get
  1393.     End Property
  1394.  
  1395.     Private _LockWidth As Integer
  1396.     Protected Property LockWidth() As Integer
  1397.         Get
  1398.             Return _LockWidth
  1399.         End Get
  1400.         Set(ByVal value As Integer)
  1401.             _LockWidth = value
  1402.             If Not LockWidth = 0 AndAlso IsHandleCreated Then Width = LockWidth
  1403.         End Set
  1404.     End Property
  1405.  
  1406.     Private _LockHeight As Integer
  1407.     Protected Property LockHeight() As Integer
  1408.         Get
  1409.             Return _LockHeight
  1410.         End Get
  1411.         Set(ByVal value As Integer)
  1412.             _LockHeight = value
  1413.             If Not LockHeight = 0 AndAlso IsHandleCreated Then Height = LockHeight
  1414.         End Set
  1415.     End Property
  1416.  
  1417.     Private _IsAnimated As Boolean
  1418.     Protected Property IsAnimated() As Boolean
  1419.         Get
  1420.             Return _IsAnimated
  1421.         End Get
  1422.         Set(ByVal value As Boolean)
  1423.             _IsAnimated = value
  1424.             InvalidateTimer()
  1425.         End Set
  1426.     End Property
  1427.  
  1428. #End Region
  1429.  
  1430.  
  1431. #Region " Property Helpers "
  1432.  
  1433.     Protected Function GetPen(ByVal name As String) As Pen
  1434.         Return New Pen(Items(name))
  1435.     End Function
  1436.     Protected Function GetPen(ByVal name As String, ByVal width As Single) As Pen
  1437.         Return New Pen(Items(name), width)
  1438.     End Function
  1439.  
  1440.     Protected Function GetBrush(ByVal name As String) As SolidBrush
  1441.         Return New SolidBrush(Items(name))
  1442.     End Function
  1443.  
  1444.     Protected Function GetColor(ByVal name As String) As Color
  1445.         Return Items(name)
  1446.     End Function
  1447.  
  1448.     Protected Sub SetColor(ByVal name As String, ByVal value As Color)
  1449.         If Items.ContainsKey(name) Then Items(name) = value Else Items.Add(name, value)
  1450.     End Sub
  1451.     Protected Sub SetColor(ByVal name As String, ByVal r As Byte, ByVal g As Byte, ByVal b As Byte)
  1452.         SetColor(name, Color.FromArgb(r, g, b))
  1453.     End Sub
  1454.     Protected Sub SetColor(ByVal name As String, ByVal a As Byte, ByVal r As Byte, ByVal g As Byte, ByVal b As Byte)
  1455.         SetColor(name, Color.FromArgb(a, r, g, b))
  1456.     End Sub
  1457.     Protected Sub SetColor(ByVal name As String, ByVal a As Byte, ByVal value As Color)
  1458.         SetColor(name, Color.FromArgb(a, value))
  1459.     End Sub
  1460.  
  1461.     Private Sub InvalidateBitmap()
  1462.         If Width = 0 OrElse Height = 0 Then Return
  1463.         B = New Bitmap(Width, Height, PixelFormat.Format32bppPArgb)
  1464.         G = Graphics.FromImage(B)
  1465.     End Sub
  1466.  
  1467.     Private Sub InvalidateCustimization()
  1468.         Dim M As New MemoryStream(Items.Count * 4)
  1469.  
  1470.         For Each B As Bloom In Colors
  1471.             M.Write(BitConverter.GetBytes(B.Value.ToArgb), 0, 4)
  1472.         Next
  1473.  
  1474.         M.Close()
  1475.         _Customization = Convert.ToBase64String(M.ToArray)
  1476.     End Sub
  1477.  
  1478.     Private Sub InvalidateTimer()
  1479.         If DesignMode OrElse Not DoneCreation Then Return
  1480.  
  1481.         If _IsAnimated Then
  1482.             AddAnimationCallback(AddressOf DoAnimation)
  1483.         Else
  1484.             RemoveAnimationCallback(AddressOf DoAnimation)
  1485.         End If
  1486.     End Sub
  1487. #End Region
  1488.  
  1489.  
  1490. #Region " User Hooks "
  1491.  
  1492.     Protected MustOverride Sub ColorHook()
  1493.     Protected MustOverride Sub PaintHook()
  1494.  
  1495.     Protected Overridable Sub OnCreation()
  1496.     End Sub
  1497.  
  1498.     Protected Overridable Sub OnAnimation()
  1499.     End Sub
  1500.  
  1501. #End Region
  1502.  
  1503.  
  1504. #Region " Offset "
  1505.  
  1506.     Private OffsetReturnRectangle As Rectangle
  1507.     Protected Function Offset(ByVal r As Rectangle, ByVal amount As Integer) As Rectangle
  1508.         OffsetReturnRectangle = New Rectangle(r.X + amount, r.Y + amount, r.Width - (amount * 2), r.Height - (amount * 2))
  1509.         Return OffsetReturnRectangle
  1510.     End Function
  1511.  
  1512.     Private OffsetReturnSize As Size
  1513.     Protected Function Offset(ByVal s As Size, ByVal amount As Integer) As Size
  1514.         OffsetReturnSize = New Size(s.Width + amount, s.Height + amount)
  1515.         Return OffsetReturnSize
  1516.     End Function
  1517.  
  1518.     Private OffsetReturnPoint As Point
  1519.     Protected Function Offset(ByVal p As Point, ByVal amount As Integer) As Point
  1520.         OffsetReturnPoint = New Point(p.X + amount, p.Y + amount)
  1521.         Return OffsetReturnPoint
  1522.     End Function
  1523.  
  1524. #End Region
  1525.  
  1526. #Region " Center "
  1527.  
  1528.     Private CenterReturn As Point
  1529.  
  1530.     Protected Function Center(ByVal p As Rectangle, ByVal c As Rectangle) As Point
  1531.         CenterReturn = New Point((p.Width \ 2 - c.Width \ 2) + p.X + c.X, (p.Height \ 2 - c.Height \ 2) + p.Y + c.Y)
  1532.         Return CenterReturn
  1533.     End Function
  1534.     Protected Function Center(ByVal p As Rectangle, ByVal c As Size) As Point
  1535.         CenterReturn = New Point((p.Width \ 2 - c.Width \ 2) + p.X, (p.Height \ 2 - c.Height \ 2) + p.Y)
  1536.         Return CenterReturn
  1537.     End Function
  1538.  
  1539.     Protected Function Center(ByVal child As Rectangle) As Point
  1540.         Return Center(Width, Height, child.Width, child.Height)
  1541.     End Function
  1542.     Protected Function Center(ByVal child As Size) As Point
  1543.         Return Center(Width, Height, child.Width, child.Height)
  1544.     End Function
  1545.     Protected Function Center(ByVal childWidth As Integer, ByVal childHeight As Integer) As Point
  1546.         Return Center(Width, Height, childWidth, childHeight)
  1547.     End Function
  1548.  
  1549.     Protected Function Center(ByVal p As Size, ByVal c As Size) As Point
  1550.         Return Center(p.Width, p.Height, c.Width, c.Height)
  1551.     End Function
  1552.  
  1553.     Protected Function Center(ByVal pWidth As Integer, ByVal pHeight As Integer, ByVal cWidth As Integer, ByVal cHeight As Integer) As Point
  1554.         CenterReturn = New Point(pWidth \ 2 - cWidth \ 2, pHeight \ 2 - cHeight \ 2)
  1555.         Return CenterReturn
  1556.     End Function
  1557.  
  1558. #End Region
  1559.  
  1560. #Region " Measure "
  1561.  
  1562.     Private MeasureBitmap As Bitmap
  1563.     Private MeasureGraphics As Graphics
  1564.  
  1565.     Protected Function Measure() As Size
  1566.         Return MeasureGraphics.MeasureString(Text, Font, Width).ToSize
  1567.     End Function
  1568.     Protected Function Measure(ByVal text As String) As Size
  1569.         Return MeasureGraphics.MeasureString(text, Font, Width).ToSize
  1570.     End Function
  1571.  
  1572. #End Region
  1573.  
  1574.  
  1575. #Region " DrawPixel "
  1576.  
  1577.     Private DrawPixelBrush As SolidBrush
  1578.  
  1579.     Protected Sub DrawPixel(ByVal c1 As Color, ByVal x As Integer, ByVal y As Integer)
  1580.         If _Transparent Then
  1581.             B.SetPixel(x, y, c1)
  1582.         Else
  1583.             DrawPixelBrush = New SolidBrush(c1)
  1584.             G.FillRectangle(DrawPixelBrush, x, y, 1, 1)
  1585.         End If
  1586.     End Sub
  1587.  
  1588. #End Region
  1589.  
  1590. #Region " DrawCorners "
  1591.  
  1592.     Private DrawCornersBrush As SolidBrush
  1593.  
  1594.     Protected Sub DrawCorners(ByVal c1 As Color, ByVal offset As Integer)
  1595.         DrawCorners(c1, 0, 0, Width, Height, offset)
  1596.     End Sub
  1597.     Protected Sub DrawCorners(ByVal c1 As Color, ByVal r1 As Rectangle, ByVal offset As Integer)
  1598.         DrawCorners(c1, r1.X, r1.Y, r1.Width, r1.Height, offset)
  1599.     End Sub
  1600.     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)
  1601.         DrawCorners(c1, x + offset, y + offset, width - (offset * 2), height - (offset * 2))
  1602.     End Sub
  1603.  
  1604.     Protected Sub DrawCorners(ByVal c1 As Color)
  1605.         DrawCorners(c1, 0, 0, Width, Height)
  1606.     End Sub
  1607.     Protected Sub DrawCorners(ByVal c1 As Color, ByVal r1 As Rectangle)
  1608.         DrawCorners(c1, r1.X, r1.Y, r1.Width, r1.Height)
  1609.     End Sub
  1610.     Protected Sub DrawCorners(ByVal c1 As Color, ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer)
  1611.         If _NoRounding Then Return
  1612.  
  1613.         If _Transparent Then
  1614.             B.SetPixel(x, y, c1)
  1615.             B.SetPixel(x + (width - 1), y, c1)
  1616.             B.SetPixel(x, y + (height - 1), c1)
  1617.             B.SetPixel(x + (width - 1), y + (height - 1), c1)
  1618.         Else
  1619.             DrawCornersBrush = New SolidBrush(c1)
  1620.             G.FillRectangle(DrawCornersBrush, x, y, 1, 1)
  1621.             G.FillRectangle(DrawCornersBrush, x + (width - 1), y, 1, 1)
  1622.             G.FillRectangle(DrawCornersBrush, x, y + (height - 1), 1, 1)
  1623.             G.FillRectangle(DrawCornersBrush, x + (width - 1), y + (height - 1), 1, 1)
  1624.         End If
  1625.     End Sub
  1626.  
  1627. #End Region
  1628.  
  1629. #Region " DrawBorders "
  1630.  
  1631.     Protected Sub DrawBorders(ByVal p1 As Pen, ByVal offset As Integer)
  1632.         DrawBorders(p1, 0, 0, Width, Height, offset)
  1633.     End Sub
  1634.     Protected Sub DrawBorders(ByVal p1 As Pen, ByVal r As Rectangle, ByVal offset As Integer)
  1635.         DrawBorders(p1, r.X, r.Y, r.Width, r.Height, offset)
  1636.     End Sub
  1637.     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)
  1638.         DrawBorders(p1, x + offset, y + offset, width - (offset * 2), height - (offset * 2))
  1639.     End Sub
  1640.  
  1641.     Protected Sub DrawBorders(ByVal p1 As Pen)
  1642.         DrawBorders(p1, 0, 0, Width, Height)
  1643.     End Sub
  1644.     Protected Sub DrawBorders(ByVal p1 As Pen, ByVal r As Rectangle)
  1645.         DrawBorders(p1, r.X, r.Y, r.Width, r.Height)
  1646.     End Sub
  1647.     Protected Sub DrawBorders(ByVal p1 As Pen, ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer)
  1648.         G.DrawRectangle(p1, x, y, width - 1, height - 1)
  1649.     End Sub
  1650.  
  1651. #End Region
  1652.  
  1653. #Region " DrawText "
  1654.  
  1655.     Private DrawTextPoint As Point
  1656.     Private DrawTextSize As Size
  1657.  
  1658.     Protected Sub DrawText(ByVal b1 As Brush, ByVal a As HorizontalAlignment, ByVal x As Integer, ByVal y As Integer)
  1659.         DrawText(b1, Text, a, x, y)
  1660.     End Sub
  1661.     Protected Sub DrawText(ByVal b1 As Brush, ByVal text As String, ByVal a As HorizontalAlignment, ByVal x As Integer, ByVal y As Integer)
  1662.         If text.Length = 0 Then Return
  1663.  
  1664.         DrawTextSize = Measure(text)
  1665.         DrawTextPoint = Center(DrawTextSize)
  1666.  
  1667.         Select Case a
  1668.             Case HorizontalAlignment.Left
  1669.                 G.DrawString(text, Font, b1, x, DrawTextPoint.Y + y)
  1670.             Case HorizontalAlignment.Center
  1671.                 G.DrawString(text, Font, b1, DrawTextPoint.X + x, DrawTextPoint.Y + y)
  1672.             Case HorizontalAlignment.Right
  1673.                 G.DrawString(text, Font, b1, Width - DrawTextSize.Width - x, DrawTextPoint.Y + y)
  1674.         End Select
  1675.     End Sub
  1676.  
  1677.     Protected Sub DrawText(ByVal b1 As Brush, ByVal p1 As Point)
  1678.         If Text.Length = 0 Then Return
  1679.         G.DrawString(Text, Font, b1, p1)
  1680.     End Sub
  1681.     Protected Sub DrawText(ByVal b1 As Brush, ByVal x As Integer, ByVal y As Integer)
  1682.         If Text.Length = 0 Then Return
  1683.         G.DrawString(Text, Font, b1, x, y)
  1684.     End Sub
  1685.  
  1686. #End Region
  1687.  
  1688. #Region " DrawImage "
  1689.  
  1690.     Private DrawImagePoint As Point
  1691.  
  1692.     Protected Sub DrawImage(ByVal a As HorizontalAlignment, ByVal x As Integer, ByVal y As Integer)
  1693.         DrawImage(_Image, a, x, y)
  1694.     End Sub
  1695.     Protected Sub DrawImage(ByVal image As Image, ByVal a As HorizontalAlignment, ByVal x As Integer, ByVal y As Integer)
  1696.         If image Is Nothing Then Return
  1697.         DrawImagePoint = Center(image.Size)
  1698.  
  1699.         Select Case a
  1700.             Case HorizontalAlignment.Left
  1701.                 G.DrawImage(image, x, DrawImagePoint.Y + y, image.Width, image.Height)
  1702.             Case HorizontalAlignment.Center
  1703.                 G.DrawImage(image, DrawImagePoint.X + x, DrawImagePoint.Y + y, image.Width, image.Height)
  1704.             Case HorizontalAlignment.Right
  1705.                 G.DrawImage(image, Width - image.Width - x, DrawImagePoint.Y + y, image.Width, image.Height)
  1706.         End Select
  1707.     End Sub
  1708.  
  1709.     Protected Sub DrawImage(ByVal p1 As Point)
  1710.         DrawImage(_Image, p1.X, p1.Y)
  1711.     End Sub
  1712.     Protected Sub DrawImage(ByVal x As Integer, ByVal y As Integer)
  1713.         DrawImage(_Image, x, y)
  1714.     End Sub
  1715.  
  1716.     Protected Sub DrawImage(ByVal image As Image, ByVal p1 As Point)
  1717.         DrawImage(image, p1.X, p1.Y)
  1718.     End Sub
  1719.     Protected Sub DrawImage(ByVal image As Image, ByVal x As Integer, ByVal y As Integer)
  1720.         If image Is Nothing Then Return
  1721.         G.DrawImage(image, x, y, image.Width, image.Height)
  1722.     End Sub
  1723.  
  1724. #End Region
  1725.  
  1726. #Region " DrawGradient "
  1727.  
  1728.     Private DrawGradientBrush As LinearGradientBrush
  1729.     Private DrawGradientRectangle As Rectangle
  1730.  
  1731.     Protected Sub DrawGradient(ByVal blend As ColorBlend, ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer)
  1732.         DrawGradientRectangle = New Rectangle(x, y, width, height)
  1733.         DrawGradient(blend, DrawGradientRectangle)
  1734.     End Sub
  1735.     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)
  1736.         DrawGradientRectangle = New Rectangle(x, y, width, height)
  1737.         DrawGradient(blend, DrawGradientRectangle, angle)
  1738.     End Sub
  1739.  
  1740.     Protected Sub DrawGradient(ByVal blend As ColorBlend, ByVal r As Rectangle)
  1741.         DrawGradientBrush = New LinearGradientBrush(r, Color.Empty, Color.Empty, 90.0F)
  1742.         DrawGradientBrush.InterpolationColors = blend
  1743.         G.FillRectangle(DrawGradientBrush, r)
  1744.     End Sub
  1745.     Protected Sub DrawGradient(ByVal blend As ColorBlend, ByVal r As Rectangle, ByVal angle As Single)
  1746.         DrawGradientBrush = New LinearGradientBrush(r, Color.Empty, Color.Empty, angle)
  1747.         DrawGradientBrush.InterpolationColors = blend
  1748.         G.FillRectangle(DrawGradientBrush, r)
  1749.     End Sub
  1750.  
  1751.  
  1752.     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)
  1753.         DrawGradientRectangle = New Rectangle(x, y, width, height)
  1754.         DrawGradient(c1, c2, DrawGradientRectangle)
  1755.     End Sub
  1756.     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)
  1757.         DrawGradientRectangle = New Rectangle(x, y, width, height)
  1758.         DrawGradient(c1, c2, DrawGradientRectangle, angle)
  1759.     End Sub
  1760.  
  1761.     Protected Sub DrawGradient(ByVal c1 As Color, ByVal c2 As Color, ByVal r As Rectangle)
  1762.         DrawGradientBrush = New LinearGradientBrush(r, c1, c2, 90.0F)
  1763.         G.FillRectangle(DrawGradientBrush, r)
  1764.     End Sub
  1765.     Protected Sub DrawGradient(ByVal c1 As Color, ByVal c2 As Color, ByVal r As Rectangle, ByVal angle As Single)
  1766.         DrawGradientBrush = New LinearGradientBrush(r, c1, c2, angle)
  1767.         G.FillRectangle(DrawGradientBrush, r)
  1768.     End Sub
  1769.  
  1770. #End Region
  1771.  
  1772. #Region " DrawRadial "
  1773.  
  1774.     Private DrawRadialPath As GraphicsPath
  1775.     Private DrawRadialBrush1 As PathGradientBrush
  1776.     Private DrawRadialBrush2 As LinearGradientBrush
  1777.     Private DrawRadialRectangle As Rectangle
  1778.  
  1779.     Sub DrawRadial(ByVal blend As ColorBlend, ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer)
  1780.         DrawRadialRectangle = New Rectangle(x, y, width, height)
  1781.         DrawRadial(blend, DrawRadialRectangle, width \ 2, height \ 2)
  1782.     End Sub
  1783.     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)
  1784.         DrawRadialRectangle = New Rectangle(x, y, width, height)
  1785.         DrawRadial(blend, DrawRadialRectangle, center.X, center.Y)
  1786.     End Sub
  1787.     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)
  1788.         DrawRadialRectangle = New Rectangle(x, y, width, height)
  1789.         DrawRadial(blend, DrawRadialRectangle, cx, cy)
  1790.     End Sub
  1791.  
  1792.     Sub DrawRadial(ByVal blend As ColorBlend, ByVal r As Rectangle)
  1793.         DrawRadial(blend, r, r.Width \ 2, r.Height \ 2)
  1794.     End Sub
  1795.     Sub DrawRadial(ByVal blend As ColorBlend, ByVal r As Rectangle, ByVal center As Point)
  1796.         DrawRadial(blend, r, center.X, center.Y)
  1797.     End Sub
  1798.     Sub DrawRadial(ByVal blend As ColorBlend, ByVal r As Rectangle, ByVal cx As Integer, ByVal cy As Integer)
  1799.         DrawRadialPath.Reset()
  1800.         DrawRadialPath.AddEllipse(r.X, r.Y, r.Width - 1, r.Height - 1)
  1801.  
  1802.         DrawRadialBrush1 = New PathGradientBrush(DrawRadialPath)
  1803.         DrawRadialBrush1.CenterPoint = New Point(r.X + cx, r.Y + cy)
  1804.         DrawRadialBrush1.InterpolationColors = blend
  1805.  
  1806.         If G.SmoothingMode = SmoothingMode.AntiAlias Then
  1807.             G.FillEllipse(DrawRadialBrush1, r.X + 1, r.Y + 1, r.Width - 3, r.Height - 3)
  1808.         Else
  1809.             G.FillEllipse(DrawRadialBrush1, r)
  1810.         End If
  1811.     End Sub
  1812.  
  1813.  
  1814.     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)
  1815.         DrawRadialRectangle = New Rectangle(x, y, width, height)
  1816.         DrawRadial(c1, c2, DrawRadialRectangle)
  1817.     End Sub
  1818.     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)
  1819.         DrawRadialRectangle = New Rectangle(x, y, width, height)
  1820.         DrawRadial(c1, c2, DrawRadialRectangle, angle)
  1821.     End Sub
  1822.  
  1823.     Protected Sub DrawRadial(ByVal c1 As Color, ByVal c2 As Color, ByVal r As Rectangle)
  1824.         DrawRadialBrush2 = New LinearGradientBrush(r, c1, c2, 90.0F)
  1825.         G.FillEllipse(DrawRadialBrush2, r)
  1826.     End Sub
  1827.     Protected Sub DrawRadial(ByVal c1 As Color, ByVal c2 As Color, ByVal r As Rectangle, ByVal angle As Single)
  1828.         DrawRadialBrush2 = New LinearGradientBrush(r, c1, c2, angle)
  1829.         G.FillEllipse(DrawRadialBrush2, r)
  1830.     End Sub
  1831.  
  1832. #End Region
  1833.  
  1834. #Region " CreateRound "
  1835.  
  1836.     Private CreateRoundPath As GraphicsPath
  1837.     Private CreateRoundRectangle As Rectangle
  1838.  
  1839.     Function CreateRound(ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer, ByVal slope As Integer) As GraphicsPath
  1840.         CreateRoundRectangle = New Rectangle(x, y, width, height)
  1841.         Return CreateRound(CreateRoundRectangle, slope)
  1842.     End Function
  1843.  
  1844.     Function CreateRound(ByVal r As Rectangle, ByVal slope As Integer) As GraphicsPath
  1845.         CreateRoundPath = New GraphicsPath(FillMode.Winding)
  1846.         CreateRoundPath.AddArc(r.X, r.Y, slope, slope, 180.0F, 90.0F)
  1847.         CreateRoundPath.AddArc(r.Right - slope, r.Y, slope, slope, 270.0F, 90.0F)
  1848.         CreateRoundPath.AddArc(r.Right - slope, r.Bottom - slope, slope, slope, 0.0F, 90.0F)
  1849.         CreateRoundPath.AddArc(r.X, r.Bottom - slope, slope, slope, 90.0F, 90.0F)
  1850.         CreateRoundPath.CloseFigure()
  1851.         Return CreateRoundPath
  1852.     End Function
  1853.  
  1854. #End Region
  1855.  
  1856. End Class
  1857.  
  1858. Module ThemeShare
  1859.  
  1860. #Region " Animation "
  1861.  
  1862.     Private Frames As Integer
  1863.     Private Invalidate As Boolean
  1864.     Public ThemeTimer As New PrecisionTimer
  1865.  
  1866.     Private Const FPS As Integer = 50
  1867.     Private Const Rate As Integer = 10
  1868.  
  1869.     Public Delegate Sub AnimationDelegate(ByVal invalidate As Boolean)
  1870.  
  1871.     Private Callbacks As New List(Of AnimationDelegate)
  1872.  
  1873.     Private Sub HandleCallbacks(ByVal state As IntPtr, ByVal reserve As Boolean)
  1874.         Invalidate = (Frames >= FPS)
  1875.         If Invalidate Then Frames = 0
  1876.  
  1877.         SyncLock Callbacks
  1878.             For I As Integer = 0 To Callbacks.Count - 1
  1879.                 Callbacks(I).Invoke(Invalidate)
  1880.             Next
  1881.         End SyncLock
  1882.  
  1883.         Frames += Rate
  1884.     End Sub
  1885.  
  1886.     Private Sub InvalidateThemeTimer()
  1887.         If Callbacks.Count = 0 Then
  1888.             ThemeTimer.Delete()
  1889.         Else
  1890.             ThemeTimer.Create(0, Rate, AddressOf HandleCallbacks)
  1891.         End If
  1892.     End Sub
  1893.  
  1894.     Sub AddAnimationCallback(ByVal callback As AnimationDelegate)
  1895.         SyncLock Callbacks
  1896.             If Callbacks.Contains(callback) Then Return
  1897.  
  1898.             Callbacks.Add(callback)
  1899.             InvalidateThemeTimer()
  1900.         End SyncLock
  1901.     End Sub
  1902.  
  1903.     Sub RemoveAnimationCallback(ByVal callback As AnimationDelegate)
  1904.         SyncLock Callbacks
  1905.             If Not Callbacks.Contains(callback) Then Return
  1906.  
  1907.             Callbacks.Remove(callback)
  1908.             InvalidateThemeTimer()
  1909.         End SyncLock
  1910.     End Sub
  1911.  
  1912. #End Region
  1913.  
  1914. End Module
  1915.  
  1916. Enum MouseState As Byte
  1917.     None = 0
  1918.     Over = 1
  1919.     Down = 2
  1920.     Block = 3
  1921. End Enum
  1922.  
  1923. Structure Bloom
  1924.  
  1925.     Public _Name As String
  1926.     ReadOnly Property Name() As String
  1927.         Get
  1928.             Return _Name
  1929.         End Get
  1930.     End Property
  1931.  
  1932.     Private _Value As Color
  1933.     Property Value() As Color
  1934.         Get
  1935.             Return _Value
  1936.         End Get
  1937.         Set(ByVal value As Color)
  1938.             _Value = value
  1939.         End Set
  1940.     End Property
  1941.  
  1942.     Property ValueHex() As String
  1943.         Get
  1944.             Return String.Concat("#", _
  1945.             _Value.R.ToString("X2", Nothing), _
  1946.             _Value.G.ToString("X2", Nothing), _
  1947.             _Value.B.ToString("X2", Nothing))
  1948.         End Get
  1949.         Set(ByVal value As String)
  1950.             Try
  1951.                 _Value = ColorTranslator.FromHtml(value)
  1952.             Catch
  1953.                 Return
  1954.             End Try
  1955.         End Set
  1956.     End Property
  1957.  
  1958.  
  1959.     Sub New(ByVal name As String, ByVal value As Color)
  1960.         _Name = name
  1961.         _Value = value
  1962.     End Sub
  1963. End Structure
  1964.  
  1965. Class PrecisionTimer
  1966.     Implements IDisposable
  1967.  
  1968.     Private _Enabled As Boolean
  1969.     ReadOnly Property Enabled() As Boolean
  1970.         Get
  1971.             Return _Enabled
  1972.         End Get
  1973.     End Property
  1974.  
  1975.     Private Handle As IntPtr
  1976.     Private TimerCallback As TimerDelegate
  1977.  
  1978.     <DllImport("kernel32.dll", EntryPoint:="CreateTimerQueueTimer")> _
  1979.     Private Shared Function CreateTimerQueueTimer( _
  1980.     ByRef handle As IntPtr, _
  1981.     ByVal queue As IntPtr, _
  1982.     ByVal callback As TimerDelegate, _
  1983.     ByVal state As IntPtr, _
  1984.     ByVal dueTime As UInteger, _
  1985.     ByVal period As UInteger, _
  1986.     ByVal flags As UInteger) As Boolean
  1987.     End Function
  1988.  
  1989.     <DllImport("kernel32.dll", EntryPoint:="DeleteTimerQueueTimer")> _
  1990.     Private Shared Function DeleteTimerQueueTimer( _
  1991.     ByVal queue As IntPtr, _
  1992.     ByVal handle As IntPtr, _
  1993.     ByVal callback As IntPtr) As Boolean
  1994.     End Function
  1995.  
  1996.     Delegate Sub TimerDelegate(ByVal r1 As IntPtr, ByVal r2 As Boolean)
  1997.  
  1998.     Sub Create(ByVal dueTime As UInteger, ByVal period As UInteger, ByVal callback As TimerDelegate)
  1999.         If _Enabled Then Return
  2000.  
  2001.         TimerCallback = callback
  2002.         Dim Success As Boolean = CreateTimerQueueTimer(Handle, IntPtr.Zero, TimerCallback, IntPtr.Zero, dueTime, period, 0)
  2003.  
  2004.         If Not Success Then ThrowNewException("CreateTimerQueueTimer")
  2005.         _Enabled = Success
  2006.     End Sub
  2007.  
  2008.     Sub Delete()
  2009.         If Not _Enabled Then Return
  2010.         Dim Success As Boolean = DeleteTimerQueueTimer(IntPtr.Zero, Handle, IntPtr.Zero)
  2011.  
  2012.         If Not Success AndAlso Not Marshal.GetLastWin32Error = 997 Then
  2013.             ThrowNewException("DeleteTimerQueueTimer")
  2014.         End If
  2015.  
  2016.         _Enabled = Not Success
  2017.     End Sub
  2018.  
  2019.     Private Sub ThrowNewException(ByVal name As String)
  2020.         Throw New Exception(String.Format("{0} failed. Win32Error: {1}", name, Marshal.GetLastWin32Error))
  2021.     End Sub
  2022.  
  2023.     Public Sub Dispose() Implements IDisposable.Dispose
  2024.         Delete()
  2025.     End Sub
  2026. End Class
  2027.  
  2028. #End Region
Advertisement
Add Comment
Please, Sign In to add comment