Guest User

[VB.NET] Hackforums Theme

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