Advertisement
Guest User

ThemeBase154

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