Advertisement
Guest User

Vitality Theme

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