Guest User

ClarityTheme

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