ImaFoSho

[VB] Complex Theme

Nov 17th, 2012
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 47.43 KB | None | 0 0
  1. Imports System, System.IO, System.Collections.Generic, System.ComponentModel, System.Windows.Forms, System.Drawing, System.Drawing.Drawing2D
  2.  
  3. '------------------
  4. 'Creator: FoSho
  5. 'Version: 1.0.0.0
  6. 'ThemeBase: Aeonhack
  7. '------------------
  8.  
  9. MustInherit Class ThemeContainer151
  10.     Inherits ContainerControl
  11.  
  12.     Protected G As Graphics
  13.  
  14.     Sub New()
  15.         SetStyle(DirectCast(139270, ControlStyles), True)
  16.         _ImageSize = Size.Empty
  17.  
  18.         MeasureBitmap = New Bitmap(1, 1)
  19.         MeasureGraphics = Graphics.FromImage(MeasureBitmap)
  20.  
  21.         Font = New Font("Verdana", 8S)
  22.  
  23.         InvalidateCustimization()
  24.     End Sub
  25.  
  26.     Protected Overrides Sub SetBoundsCore(ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer, ByVal specified As BoundsSpecified)
  27.         If Not _LockWidth = 0 Then width = _LockWidth
  28.         If Not _LockHeight = 0 Then height = _LockHeight
  29.         MyBase.SetBoundsCore(x, y, width, height, specified)
  30.     End Sub
  31.  
  32.     Private Header As Rectangle
  33.     Protected NotOverridable Overrides Sub OnSizeChanged(ByVal e As EventArgs)
  34.         MyBase.OnSizeChanged(e)
  35.         If _Movable AndAlso Not _ControlMode Then Header = New Rectangle(7, 7, Width - 14, _MoveHeight - 7)
  36.         Invalidate()
  37.     End Sub
  38.  
  39.     Protected NotOverridable Overrides Sub OnPaint(ByVal e As PaintEventArgs)
  40.         If Width = 0 OrElse Height = 0 Then Return
  41.         G = e.Graphics
  42.         PaintHook()
  43.     End Sub
  44.  
  45.     Protected NotOverridable Overrides Sub OnHandleCreated(ByVal e As EventArgs)
  46.         InitializeMessages()
  47.         InvalidateCustimization()
  48.         ColorHook()
  49.  
  50.         _IsParentForm = TypeOf Parent Is Form
  51.         If Not _ControlMode Then Dock = DockStyle.Fill
  52.  
  53.         If Not _LockWidth = 0 Then Width = _LockWidth
  54.         If Not _LockHeight = 0 Then Height = _LockHeight
  55.         If Not BackColorWait = Nothing Then BackColor = BackColorWait
  56.  
  57.         If _IsParentForm AndAlso Not _ControlMode Then
  58.             ParentForm.FormBorderStyle = _BorderStyle
  59.             ParentForm.TransparencyKey = _TransparencyKey
  60.         End If
  61.  
  62.         OnCreation()
  63.         MyBase.OnHandleCreated(e)
  64.     End Sub
  65.  
  66.     Protected Overridable Sub OnCreation()
  67.     End Sub
  68.  
  69. #Region " Sizing and Movement "
  70.  
  71.     Protected State As MouseState
  72.     Private Sub SetState(ByVal current As MouseState)
  73.         State = current
  74.         Invalidate()
  75.     End Sub
  76.  
  77.     Protected Overrides Sub OnMouseMove(ByVal e As MouseEventArgs)
  78.         If _Sizable AndAlso Not _ControlMode Then InvalidateMouse()
  79.         MyBase.OnMouseMove(e)
  80.     End Sub
  81.  
  82.     Protected Overrides Sub OnEnabledChanged(ByVal e As EventArgs)
  83.         If Enabled Then SetState(MouseState.None) Else SetState(MouseState.Block)
  84.         MyBase.OnEnabledChanged(e)
  85.     End Sub
  86.  
  87.     Protected Overrides Sub OnMouseEnter(ByVal e As EventArgs)
  88.         SetState(MouseState.Over)
  89.         MyBase.OnMouseEnter(e)
  90.     End Sub
  91.  
  92.     Protected Overrides Sub OnMouseUp(ByVal e As MouseEventArgs)
  93.         SetState(MouseState.Over)
  94.         MyBase.OnMouseUp(e)
  95.     End Sub
  96.  
  97.     Protected Overrides Sub OnMouseLeave(ByVal e As EventArgs)
  98.         SetState(MouseState.None)
  99.  
  100.         If _Sizable AndAlso Not _ControlMode AndAlso GetChildAtPoint(PointToClient(MousePosition)) IsNot Nothing Then
  101.             Cursor = Cursors.Default
  102.             Previous = 0
  103.         End If
  104.  
  105.         MyBase.OnMouseLeave(e)
  106.     End Sub
  107.  
  108.     Protected Overrides Sub OnMouseDown(ByVal e As MouseEventArgs)
  109.         MyBase.OnMouseDown(e)
  110.  
  111.         If Not e.Button = Windows.Forms.MouseButtons.Left Then Return
  112.         SetState(MouseState.Down)
  113.  
  114.         If _IsParentForm AndAlso ParentForm.WindowState = FormWindowState.Maximized OrElse _ControlMode Then Return
  115.  
  116.         If _Movable AndAlso Header.Contains(e.Location) Then
  117.             Capture = False
  118.             DefWndProc(Messages(0))
  119.         ElseIf _Sizable AndAlso Not Previous = 0 Then
  120.             Capture = False
  121.             DefWndProc(Messages(Previous))
  122.         End If
  123.     End Sub
  124.  
  125.     Private GetIndexPoint As Point
  126.     Private B1, B2, B3, B4 As Boolean
  127.     Private Function GetIndex() As Integer
  128.         GetIndexPoint = PointToClient(MousePosition)
  129.         B1 = GetIndexPoint.X < 7
  130.         B2 = GetIndexPoint.X > Width - 7
  131.         B3 = GetIndexPoint.Y < 7
  132.         B4 = GetIndexPoint.Y > Height - 7
  133.  
  134.         If B1 AndAlso B3 Then Return 4
  135.         If B1 AndAlso B4 Then Return 7
  136.         If B2 AndAlso B3 Then Return 5
  137.         If B2 AndAlso B4 Then Return 8
  138.         If B1 Then Return 1
  139.         If B2 Then Return 2
  140.         If B3 Then Return 3
  141.         If B4 Then Return 6
  142.         Return 0
  143.     End Function
  144.  
  145.     Private Current, Previous As Integer
  146.     Private Sub InvalidateMouse()
  147.         Current = GetIndex()
  148.         If Current = Previous Then Return
  149.  
  150.         Previous = Current
  151.         Select Case Previous
  152.             Case 0
  153.                 Cursor = Cursors.Default
  154.             Case 1, 2
  155.                 Cursor = Cursors.SizeWE
  156.             Case 3, 6
  157.                 Cursor = Cursors.SizeNS
  158.             Case 4, 8
  159.                 Cursor = Cursors.SizeNWSE
  160.             Case 5, 7
  161.                 Cursor = Cursors.SizeNESW
  162.         End Select
  163.     End Sub
  164.  
  165.     Private Messages(8) As Message
  166.     Private Sub InitializeMessages()
  167.         Messages(0) = Message.Create(Parent.Handle, 161, New IntPtr(2), IntPtr.Zero)
  168.         For I As Integer = 1 To 8
  169.             Messages(I) = Message.Create(Parent.Handle, 161, New IntPtr(I + 9), IntPtr.Zero)
  170.         Next
  171.     End Sub
  172.  
  173. #End Region
  174.  
  175.  
  176. #Region " Property Overrides "
  177.  
  178.     Private BackColorWait As Color
  179.     Overrides Property BackColor() As Color
  180.         Get
  181.             Return MyBase.BackColor
  182.         End Get
  183.         Set(ByVal value As Color)
  184.             If IsHandleCreated Then
  185.                 If Not _ControlMode Then Parent.BackColor = value
  186.                 MyBase.BackColor = value
  187.             Else
  188.                 BackColorWait = value
  189.             End If
  190.         End Set
  191.     End Property
  192.  
  193.     <Browsable(False), EditorBrowsable(EditorBrowsableState.Never), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _
  194.     Overrides Property ForeColor() As Color
  195.         Get
  196.             Return Color.Empty
  197.         End Get
  198.         Set(ByVal value As Color)
  199.         End Set
  200.     End Property
  201.     <Browsable(False), EditorBrowsable(EditorBrowsableState.Never), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _
  202.     Overrides Property BackgroundImage() As Image
  203.         Get
  204.             Return Nothing
  205.         End Get
  206.         Set(ByVal value As Image)
  207.         End Set
  208.     End Property
  209.     <Browsable(False), EditorBrowsable(EditorBrowsableState.Never), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _
  210.     Overrides Property BackgroundImageLayout() As ImageLayout
  211.         Get
  212.             Return ImageLayout.None
  213.         End Get
  214.         Set(ByVal value As ImageLayout)
  215.         End Set
  216.     End Property
  217.  
  218.     Overrides Property Text() As String
  219.         Get
  220.             Return MyBase.Text
  221.         End Get
  222.         Set(ByVal value As String)
  223.             MyBase.Text = value
  224.             Invalidate()
  225.         End Set
  226.     End Property
  227.  
  228.     Overrides Property Font() As Font
  229.         Get
  230.             Return MyBase.Font
  231.         End Get
  232.         Set(ByVal value As Font)
  233.             MyBase.Font = value
  234.             Invalidate()
  235.         End Set
  236.     End Property
  237.  
  238. #End Region
  239.  
  240. #Region " Properties "
  241.  
  242.     Private _Movable As Boolean = True
  243.     Property Movable() As Boolean
  244.         Get
  245.             Return _Movable
  246.         End Get
  247.         Set(ByVal value As Boolean)
  248.             _Movable = value
  249.         End Set
  250.     End Property
  251.  
  252.     Private _Sizable As Boolean = True
  253.     Property Sizable() As Boolean
  254.         Get
  255.             Return _Sizable
  256.         End Get
  257.         Set(ByVal value As Boolean)
  258.             _Sizable = value
  259.         End Set
  260.     End Property
  261.  
  262.     Private _MoveHeight As Integer = 24
  263.     Protected Property MoveHeight() As Integer
  264.         Get
  265.             Return _MoveHeight
  266.         End Get
  267.         Set(ByVal v As Integer)
  268.             If v < 8 Then Return
  269.             Header = New Rectangle(7, 7, Width - 14, v - 7)
  270.             _MoveHeight = v
  271.             Invalidate()
  272.         End Set
  273.     End Property
  274.  
  275.     Private _ControlMode As Boolean
  276.     Protected Property ControlMode() As Boolean
  277.         Get
  278.             Return _ControlMode
  279.         End Get
  280.         Set(ByVal v As Boolean)
  281.             _ControlMode = v
  282.         End Set
  283.     End Property
  284.  
  285.     Private _TransparencyKey As Color
  286.     Property TransparencyKey() As Color
  287.         Get
  288.             If _IsParentForm AndAlso Not _ControlMode Then Return ParentForm.TransparencyKey Else Return _TransparencyKey
  289.         End Get
  290.         Set(ByVal value As Color)
  291.             If _IsParentForm AndAlso Not _ControlMode Then ParentForm.TransparencyKey = value
  292.             _TransparencyKey = value
  293.         End Set
  294.     End Property
  295.  
  296.     Private _BorderStyle As FormBorderStyle
  297.     Property BorderStyle() As FormBorderStyle
  298.         Get
  299.             If _IsParentForm AndAlso Not _ControlMode Then Return ParentForm.FormBorderStyle Else Return _BorderStyle
  300.         End Get
  301.         Set(ByVal value As FormBorderStyle)
  302.             If _IsParentForm AndAlso Not _ControlMode Then ParentForm.FormBorderStyle = value
  303.             _BorderStyle = value
  304.         End Set
  305.     End Property
  306.  
  307.     Private _NoRounding As Boolean
  308.     Property NoRounding() As Boolean
  309.         Get
  310.             Return _NoRounding
  311.         End Get
  312.         Set(ByVal v As Boolean)
  313.             _NoRounding = v
  314.             Invalidate()
  315.         End Set
  316.     End Property
  317.  
  318.     Private _Image As Image
  319.     Property Image() As Image
  320.         Get
  321.             Return _Image
  322.         End Get
  323.         Set(ByVal value As Image)
  324.             If value Is Nothing Then
  325.                 _ImageSize = Size.Empty
  326.             Else
  327.                 _ImageSize = value.Size
  328.             End If
  329.  
  330.             _Image = value
  331.             Invalidate()
  332.         End Set
  333.     End Property
  334.  
  335.     Private _ImageSize As Size
  336.     Protected ReadOnly Property ImageSize() As Size
  337.         Get
  338.             Return _ImageSize
  339.         End Get
  340.     End Property
  341.  
  342.     Private _IsParentForm As Boolean
  343.     Protected ReadOnly Property IsParentForm As Boolean
  344.         Get
  345.             Return _IsParentForm
  346.         End Get
  347.     End Property
  348.  
  349.     Private _LockWidth As Integer
  350.     Protected Property LockWidth() As Integer
  351.         Get
  352.             Return _LockWidth
  353.         End Get
  354.         Set(ByVal value As Integer)
  355.             _LockWidth = value
  356.             If Not LockWidth = 0 AndAlso IsHandleCreated Then Width = LockWidth
  357.         End Set
  358.     End Property
  359.  
  360.     Private _LockHeight As Integer
  361.     Protected Property LockHeight() As Integer
  362.         Get
  363.             Return _LockHeight
  364.         End Get
  365.         Set(ByVal value As Integer)
  366.             _LockHeight = value
  367.             If Not LockHeight = 0 AndAlso IsHandleCreated Then Height = LockHeight
  368.         End Set
  369.     End Property
  370.  
  371.     Private Items As New Dictionary(Of String, Color)
  372.     <DesignerSerializationVisibility(DesignerSerializationVisibility.Content)> _
  373.     Property Colors() As Bloom()
  374.         Get
  375.             Dim T As New List(Of Bloom)
  376.             Dim E As Dictionary(Of String, Color).Enumerator = Items.GetEnumerator
  377.  
  378.             While E.MoveNext
  379.                 T.Add(New Bloom(E.Current.Key, E.Current.Value))
  380.             End While
  381.  
  382.             Return T.ToArray
  383.         End Get
  384.         Set(ByVal value As Bloom())
  385.             For Each B As Bloom In value
  386.                 If Items.ContainsKey(B.Name) Then Items(B.Name) = B.Value
  387.             Next
  388.  
  389.             InvalidateCustimization()
  390.             ColorHook()
  391.             Invalidate()
  392.         End Set
  393.     End Property
  394.  
  395.     Private _Customization As String
  396.     Property Customization() As String
  397.         Get
  398.             Return _Customization
  399.         End Get
  400.         Set(ByVal value As String)
  401.             If value = _Customization Then Return
  402.  
  403.             Dim Data As Byte()
  404.             Dim Items As Bloom() = Colors
  405.  
  406.             Try
  407.                 Data = Convert.FromBase64String(value)
  408.                 For I As Integer = 0 To Items.Length - 1
  409.                     Items(I).Value = Color.FromArgb(BitConverter.ToInt32(Data, I * 4))
  410.                 Next
  411.             Catch
  412.                 Return
  413.             End Try
  414.  
  415.             _Customization = value
  416.  
  417.             Colors = Items
  418.             ColorHook()
  419.             Invalidate()
  420.         End Set
  421.     End Property
  422.  
  423. #End Region
  424.  
  425. #Region " Property Helpers "
  426.  
  427.     Protected Function GetColor(ByVal name As String) As Color
  428.         Return Items(name)
  429.     End Function
  430.  
  431.     Protected Sub SetColor(ByVal name As String, ByVal color As Color)
  432.         If Items.ContainsKey(name) Then Items(name) = color Else Items.Add(name, color)
  433.     End Sub
  434.     Protected Sub SetColor(ByVal name As String, ByVal r As Byte, ByVal g As Byte, ByVal b As Byte)
  435.         SetColor(name, Color.FromArgb(r, g, b))
  436.     End Sub
  437.     Protected Sub SetColor(ByVal name As String, ByVal a As Byte, ByVal r As Byte, ByVal g As Byte, ByVal b As Byte)
  438.         SetColor(name, Color.FromArgb(a, r, g, b))
  439.     End Sub
  440.     Protected Sub SetColor(ByVal name As String, ByVal a As Byte, ByVal color As Color)
  441.         SetColor(name, color.FromArgb(a, color))
  442.     End Sub
  443.  
  444.     Private Sub InvalidateCustimization()
  445.         Dim M As New MemoryStream(Items.Count * 4)
  446.  
  447.         For Each B As Bloom In Colors
  448.             M.Write(BitConverter.GetBytes(B.Value.ToArgb), 0, 4)
  449.         Next
  450.  
  451.         M.Close()
  452.         _Customization = Convert.ToBase64String(M.ToArray)
  453.     End Sub
  454.  
  455. #End Region
  456.  
  457.  
  458. #Region " User Hooks "
  459.  
  460.     Protected MustOverride Sub ColorHook()
  461.     Protected MustOverride Sub PaintHook()
  462.  
  463. #End Region
  464.  
  465.  
  466. #Region " Center Overloads "
  467.  
  468.     Private CenterReturn As Point
  469.  
  470.     Protected Function Center(ByVal r1 As Rectangle, ByVal s1 As Size) As Point
  471.         CenterReturn = New Point((r1.Width \ 2 - s1.Width \ 2) + r1.X, (r1.Height \ 2 - s1.Height \ 2) + r1.Y)
  472.         Return CenterReturn
  473.     End Function
  474.     Protected Function Center(ByVal r1 As Rectangle, ByVal r2 As Rectangle) As Point
  475.         Return Center(r1, r2.Size)
  476.     End Function
  477.  
  478.     Protected Function Center(ByVal w1 As Integer, ByVal h1 As Integer, ByVal w2 As Integer, ByVal h2 As Integer) As Point
  479.         CenterReturn = New Point(w1 \ 2 - w2 \ 2, h1 \ 2 - h2 \ 2)
  480.         Return CenterReturn
  481.     End Function
  482.  
  483.     Protected Function Center(ByVal s1 As Size, ByVal s2 As Size) As Point
  484.         Return Center(s1.Width, s1.Height, s2.Width, s2.Height)
  485.     End Function
  486.  
  487.     Protected Function Center(ByVal r1 As Rectangle) As Point
  488.         Return Center(ClientRectangle.Width, ClientRectangle.Height, r1.Width, r1.Height)
  489.     End Function
  490.     Protected Function Center(ByVal s1 As Size) As Point
  491.         Return Center(Width, Height, s1.Width, s1.Height)
  492.     End Function
  493.     Protected Function Center(ByVal w1 As Integer, ByVal h1 As Integer) As Point
  494.         Return Center(Width, Height, w1, h1)
  495.     End Function
  496.  
  497. #End Region
  498.  
  499. #Region " Measure Overloads "
  500.  
  501.     Private MeasureBitmap As Bitmap
  502.     Private MeasureGraphics As Graphics
  503.  
  504.     Protected Function Measure(ByVal text As String) As Size
  505.         Return MeasureGraphics.MeasureString(text, Font, Width).ToSize
  506.     End Function
  507.     Protected Function Measure() As Size
  508.         Return MeasureGraphics.MeasureString(Text, Font).ToSize
  509.     End Function
  510.  
  511. #End Region
  512.  
  513. #Region " DrawCorners Overloads "
  514.  
  515.     'TODO: Optimize by checking brush color
  516.  
  517.     Private DrawCornersBrush As SolidBrush
  518.  
  519.     Protected Sub DrawCorners(ByVal c1 As Color)
  520.         DrawCorners(c1, 0, 0, Width, Height)
  521.     End Sub
  522.     Protected Sub DrawCorners(ByVal c1 As Color, ByVal r1 As Rectangle)
  523.         DrawCorners(c1, r1.X, r1.Y, r1.Width, r1.Height)
  524.     End Sub
  525.     Protected Sub DrawCorners(ByVal c1 As Color, ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer)
  526.         If _NoRounding Then Return
  527.  
  528.         DrawCornersBrush = New SolidBrush(c1)
  529.         G.FillRectangle(DrawCornersBrush, x, y, 1, 1)
  530.         G.FillRectangle(DrawCornersBrush, x + (width - 1), y, 1, 1)
  531.         G.FillRectangle(DrawCornersBrush, x, y + (height - 1), 1, 1)
  532.         G.FillRectangle(DrawCornersBrush, x + (width - 1), y + (height - 1), 1, 1)
  533.     End Sub
  534.  
  535. #End Region
  536.  
  537. #Region " DrawBorders Overloads "
  538.  
  539.     'TODO: Remove triple overload?
  540.  
  541.     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)
  542.         DrawBorders(p1, x + offset, y + offset, width - (offset * 2), height - (offset * 2))
  543.     End Sub
  544.     Protected Sub DrawBorders(ByVal p1 As Pen, ByVal offset As Integer)
  545.         DrawBorders(p1, 0, 0, Width, Height, offset)
  546.     End Sub
  547.     Protected Sub DrawBorders(ByVal p1 As Pen, ByVal r As Rectangle, ByVal offset As Integer)
  548.         DrawBorders(p1, r.X, r.Y, r.Width, r.Height, offset)
  549.     End Sub
  550.  
  551.     Protected Sub DrawBorders(ByVal p1 As Pen, ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer)
  552.         G.DrawRectangle(p1, x, y, width - 1, height - 1)
  553.     End Sub
  554.     Protected Sub DrawBorders(ByVal p1 As Pen)
  555.         DrawBorders(p1, 0, 0, Width, Height)
  556.     End Sub
  557.     Protected Sub DrawBorders(ByVal p1 As Pen, ByVal r As Rectangle)
  558.         DrawBorders(p1, r.X, r.Y, r.Width, r.Height)
  559.     End Sub
  560.  
  561. #End Region
  562.  
  563. #Region " DrawText Overloads "
  564.  
  565.     'TODO: Remove triple overloads?
  566.  
  567.     Private DrawTextPoint As Point
  568.     Private DrawTextSize As Size
  569.  
  570.     Protected Sub DrawText(ByVal b1 As Brush, ByVal a As HorizontalAlignment, ByVal x As Integer, ByVal y As Integer)
  571.         DrawText(b1, Text, a, x, y)
  572.     End Sub
  573.     Protected Sub DrawText(ByVal b1 As Brush, ByVal p1 As Point)
  574.         DrawText(b1, Text, p1.X, p1.Y)
  575.     End Sub
  576.     Protected Sub DrawText(ByVal b1 As Brush, ByVal x As Integer, ByVal y As Integer)
  577.         DrawText(b1, Text, x, y)
  578.     End Sub
  579.  
  580.     Protected Sub DrawText(ByVal b1 As Brush, ByVal text As String, ByVal a As HorizontalAlignment, ByVal x As Integer, ByVal y As Integer)
  581.         If text.Length = 0 Then Return
  582.         DrawTextSize = Measure(text)
  583.         DrawTextPoint = New Point(Width \ 2 - DrawTextSize.Width \ 2, MoveHeight \ 2 - DrawTextSize.Height \ 2)
  584.  
  585.         Select Case a
  586.             Case HorizontalAlignment.Left
  587.                 DrawText(b1, text, x, DrawTextPoint.Y + y)
  588.             Case HorizontalAlignment.Center
  589.                 DrawText(b1, text, DrawTextPoint.X + x, DrawTextPoint.Y + y)
  590.             Case HorizontalAlignment.Right
  591.                 DrawText(b1, text, Width - DrawTextSize.Width - x, DrawTextPoint.Y + y)
  592.         End Select
  593.     End Sub
  594.     Protected Sub DrawText(ByVal b1 As Brush, ByVal text As String, ByVal p1 As Point)
  595.         DrawText(b1, text, p1.X, p1.Y)
  596.     End Sub
  597.     Protected Sub DrawText(ByVal b1 As Brush, ByVal text As String, ByVal x As Integer, ByVal y As Integer)
  598.         If text.Length = 0 Then Return
  599.         G.DrawString(text, Font, b1, x, y)
  600.     End Sub
  601.  
  602. #End Region
  603.  
  604. #Region " DrawImage Overloads "
  605.  
  606.     'TODO: Remove triple overloads?
  607.  
  608.     Private DrawImagePoint As Point
  609.  
  610.     Protected Sub DrawImage(ByVal a As HorizontalAlignment, ByVal x As Integer, ByVal y As Integer)
  611.         DrawImage(_Image, a, x, y)
  612.     End Sub
  613.     Protected Sub DrawImage(ByVal p1 As Point)
  614.         DrawImage(_Image, p1.X, p1.Y)
  615.     End Sub
  616.     Protected Sub DrawImage(ByVal x As Integer, ByVal y As Integer)
  617.         DrawImage(_Image, x, y)
  618.     End Sub
  619.  
  620.     Protected Sub DrawImage(ByVal image As Image, ByVal a As HorizontalAlignment, ByVal x As Integer, ByVal y As Integer)
  621.         If image Is Nothing Then Return
  622.         DrawImagePoint = New Point(Width \ 2 - image.Width \ 2, MoveHeight \ 2 - image.Height \ 2)
  623.  
  624.         Select Case a
  625.             Case HorizontalAlignment.Left
  626.                 DrawImage(image, x, DrawImagePoint.Y + y)
  627.             Case HorizontalAlignment.Center
  628.                 DrawImage(image, DrawImagePoint.X + x, DrawImagePoint.Y + y)
  629.             Case HorizontalAlignment.Right
  630.                 DrawImage(image, Width - image.Width - x, DrawImagePoint.Y + y)
  631.         End Select
  632.     End Sub
  633.     Protected Sub DrawImage(ByVal image As Image, ByVal p1 As Point)
  634.         DrawImage(image, p1.X, p1.Y)
  635.     End Sub
  636.     Protected Sub DrawImage(ByVal image As Image, ByVal x As Integer, ByVal y As Integer)
  637.         If image Is Nothing Then Return
  638.         G.DrawImage(image, x, y, image.Width, image.Height)
  639.     End Sub
  640.  
  641. #End Region
  642.  
  643. #Region " DrawGradient Overloads "
  644.  
  645.     'TODO: Remove triple overload?
  646.  
  647.     Private DrawGradientBrush As LinearGradientBrush
  648.     Private DrawGradientRectangle As Rectangle
  649.  
  650.     Protected Sub DrawGradient(ByVal blend As ColorBlend, ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer)
  651.         DrawGradient(blend, x, y, width, height, 90S)
  652.     End Sub
  653.     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)
  654.         DrawGradient(c1, c2, x, y, width, height, 90S)
  655.     End Sub
  656.  
  657.     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)
  658.         DrawGradientRectangle = New Rectangle(x, y, width, height)
  659.         DrawGradient(blend, DrawGradientRectangle, angle)
  660.     End Sub
  661.     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)
  662.         DrawGradientRectangle = New Rectangle(x, y, width, height)
  663.         DrawGradient(c1, c2, DrawGradientRectangle, angle)
  664.     End Sub
  665.  
  666.     Protected Sub DrawGradient(ByVal blend As ColorBlend, ByVal r As Rectangle, ByVal angle As Single)
  667.         DrawGradientBrush = New LinearGradientBrush(r, Color.Empty, Color.Empty, angle)
  668.         DrawGradientBrush.InterpolationColors = blend
  669.         G.FillRectangle(DrawGradientBrush, r)
  670.     End Sub
  671.     Protected Sub DrawGradient(ByVal c1 As Color, ByVal c2 As Color, ByVal r As Rectangle, ByVal angle As Single)
  672.         DrawGradientBrush = New LinearGradientBrush(r, c1, c2, angle)
  673.         G.FillRectangle(DrawGradientBrush, r)
  674.     End Sub
  675.  
  676. #End Region
  677.  
  678. End Class
  679.  
  680. MustInherit Class ThemeControl151
  681.     Inherits Control
  682.  
  683.     Protected G As Graphics, B As Bitmap
  684.  
  685.     Sub New()
  686.         SetStyle(DirectCast(139270, ControlStyles), True)
  687.  
  688.         _ImageSize = Size.Empty
  689.  
  690.         MeasureBitmap = New Bitmap(1, 1)
  691.         MeasureGraphics = Graphics.FromImage(MeasureBitmap)
  692.  
  693.         Font = New Font("Verdana", 8S)
  694.  
  695.         InvalidateCustimization()
  696.     End Sub
  697.  
  698.     Protected Overrides Sub SetBoundsCore(ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer, ByVal specified As BoundsSpecified)
  699.         If Not _LockWidth = 0 Then width = _LockWidth
  700.         If Not _LockHeight = 0 Then height = _LockHeight
  701.         MyBase.SetBoundsCore(x, y, width, height, specified)
  702.     End Sub
  703.  
  704.     Protected NotOverridable Overrides Sub OnSizeChanged(ByVal e As EventArgs)
  705.         If _Transparent AndAlso Not (Width = 0 OrElse Height = 0) Then
  706.             B = New Bitmap(Width, Height)
  707.             G = Graphics.FromImage(B)
  708.         End If
  709.  
  710.         Invalidate()
  711.         MyBase.OnSizeChanged(e)
  712.     End Sub
  713.  
  714.     Protected NotOverridable Overrides Sub OnPaint(ByVal e As PaintEventArgs)
  715.         If Width = 0 OrElse Height = 0 Then Return
  716.  
  717.         If _Transparent Then
  718.             PaintHook()
  719.             e.Graphics.DrawImage(B, 0, 0)
  720.         Else
  721.             G = e.Graphics
  722.             PaintHook()
  723.         End If
  724.     End Sub
  725.  
  726.     Protected Overrides Sub OnHandleCreated(ByVal e As EventArgs)
  727.         InvalidateCustimization()
  728.         ColorHook()
  729.  
  730.         If Not _LockWidth = 0 Then Width = _LockWidth
  731.         If Not _LockHeight = 0 Then Height = _LockHeight
  732.         If Not BackColorWait = Nothing Then BackColor = BackColorWait
  733.  
  734.         OnCreation()
  735.         MyBase.OnHandleCreated(e)
  736.     End Sub
  737.  
  738.     Protected Overridable Sub OnCreation()
  739.     End Sub
  740.  
  741. #Region " State Handling "
  742.  
  743.     Protected Overrides Sub OnMouseEnter(ByVal e As EventArgs)
  744.         SetState(MouseState.Over)
  745.         MyBase.OnMouseEnter(e)
  746.     End Sub
  747.  
  748.     Protected Overrides Sub OnMouseUp(ByVal e As MouseEventArgs)
  749.         SetState(MouseState.Over)
  750.         MyBase.OnMouseUp(e)
  751.     End Sub
  752.  
  753.     Protected Overrides Sub OnMouseDown(ByVal e As MouseEventArgs)
  754.         If e.Button = Windows.Forms.MouseButtons.Left Then SetState(MouseState.Down)
  755.         MyBase.OnMouseDown(e)
  756.     End Sub
  757.  
  758.     Protected Overrides Sub OnMouseLeave(ByVal e As EventArgs)
  759.         SetState(MouseState.None)
  760.         MyBase.OnMouseLeave(e)
  761.     End Sub
  762.  
  763.     Protected Overrides Sub OnEnabledChanged(ByVal e As EventArgs)
  764.         If Enabled Then SetState(MouseState.None) Else SetState(MouseState.Block)
  765.         MyBase.OnEnabledChanged(e)
  766.     End Sub
  767.  
  768.     Protected State As MouseState
  769.     Private Sub SetState(ByVal current As MouseState)
  770.         State = current
  771.         Invalidate()
  772.     End Sub
  773.  
  774. #End Region
  775.  
  776.  
  777. #Region " Property Overrides "
  778.  
  779.     Private BackColorWait As Color
  780.     Overrides Property BackColor() As Color
  781.         Get
  782.             Return MyBase.BackColor
  783.         End Get
  784.         Set(ByVal value As Color)
  785.             If IsHandleCreated Then
  786.                 MyBase.BackColor = value
  787.             Else
  788.                 BackColorWait = value
  789.             End If
  790.         End Set
  791.     End Property
  792.  
  793.     <Browsable(False), EditorBrowsable(EditorBrowsableState.Never), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _
  794.     Overrides Property ForeColor() As Color
  795.         Get
  796.             Return Color.Empty
  797.         End Get
  798.         Set(ByVal value As Color)
  799.         End Set
  800.     End Property
  801.     <Browsable(False), EditorBrowsable(EditorBrowsableState.Never), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _
  802.     Overrides Property BackgroundImage() As Image
  803.         Get
  804.             Return Nothing
  805.         End Get
  806.         Set(ByVal value As Image)
  807.         End Set
  808.     End Property
  809.     <Browsable(False), EditorBrowsable(EditorBrowsableState.Never), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _
  810.     Overrides Property BackgroundImageLayout() As ImageLayout
  811.         Get
  812.             Return ImageLayout.None
  813.         End Get
  814.         Set(ByVal value As ImageLayout)
  815.         End Set
  816.     End Property
  817.  
  818.     Overrides Property Text() As String
  819.         Get
  820.             Return MyBase.Text
  821.         End Get
  822.         Set(ByVal value As String)
  823.             MyBase.Text = value
  824.             Invalidate()
  825.         End Set
  826.     End Property
  827.  
  828.     Overrides Property Font() As Font
  829.         Get
  830.             Return MyBase.Font
  831.         End Get
  832.         Set(ByVal value As Font)
  833.             MyBase.Font = value
  834.             Invalidate()
  835.         End Set
  836.     End Property
  837.  
  838. #End Region
  839.  
  840. #Region " Properties "
  841.  
  842.     Private _NoRounding As Boolean
  843.     Property NoRounding() As Boolean
  844.         Get
  845.             Return _NoRounding
  846.         End Get
  847.         Set(ByVal v As Boolean)
  848.             _NoRounding = v
  849.             Invalidate()
  850.         End Set
  851.     End Property
  852.  
  853.     Private _Image As Image
  854.     Property Image() As Image
  855.         Get
  856.             Return _Image
  857.         End Get
  858.         Set(ByVal value As Image)
  859.             If value Is Nothing Then
  860.                 _ImageSize = Size.Empty
  861.             Else
  862.                 _ImageSize = value.Size
  863.             End If
  864.  
  865.             _Image = value
  866.             Invalidate()
  867.         End Set
  868.     End Property
  869.  
  870.     Private _ImageSize As Size
  871.     Protected ReadOnly Property ImageSize() As Size
  872.         Get
  873.             Return _ImageSize
  874.         End Get
  875.     End Property
  876.  
  877.     Private _LockWidth As Integer
  878.     Protected Property LockWidth() As Integer
  879.         Get
  880.             Return _LockWidth
  881.         End Get
  882.         Set(ByVal value As Integer)
  883.             _LockWidth = value
  884.             If Not LockWidth = 0 AndAlso IsHandleCreated Then Width = LockWidth
  885.         End Set
  886.     End Property
  887.  
  888.     Private _LockHeight As Integer
  889.     Protected Property LockHeight() As Integer
  890.         Get
  891.             Return _LockHeight
  892.         End Get
  893.         Set(ByVal value As Integer)
  894.             _LockHeight = value
  895.             If Not LockHeight = 0 AndAlso IsHandleCreated Then Height = LockHeight
  896.         End Set
  897.     End Property
  898.  
  899.     Private _Transparent As Boolean
  900.     Property Transparent() As Boolean
  901.         Get
  902.             Return _Transparent
  903.         End Get
  904.         Set(ByVal value As Boolean)
  905.             If Not value AndAlso Not BackColor.A = 255 Then
  906.                 Throw New Exception("Unable to change value to false while a transparent BackColor is in use.")
  907.             End If
  908.  
  909.             SetStyle(ControlStyles.Opaque, Not value)
  910.             SetStyle(ControlStyles.SupportsTransparentBackColor, value)
  911.  
  912.             If value Then InvalidateBitmap() Else B = Nothing
  913.  
  914.             _Transparent = value
  915.             Invalidate()
  916.         End Set
  917.     End Property
  918.  
  919.     Private Items As New Dictionary(Of String, Color)
  920.     <DesignerSerializationVisibility(DesignerSerializationVisibility.Content)> _
  921.     Property Colors() As Bloom()
  922.         Get
  923.             Dim T As New List(Of Bloom)
  924.             Dim E As Dictionary(Of String, Color).Enumerator = Items.GetEnumerator
  925.  
  926.             While E.MoveNext
  927.                 T.Add(New Bloom(E.Current.Key, E.Current.Value))
  928.             End While
  929.  
  930.             Return T.ToArray
  931.         End Get
  932.         Set(ByVal value As Bloom())
  933.             For Each B As Bloom In value
  934.                 If Items.ContainsKey(B.Name) Then Items(B.Name) = B.Value
  935.             Next
  936.  
  937.             InvalidateCustimization()
  938.             ColorHook()
  939.             Invalidate()
  940.         End Set
  941.     End Property
  942.  
  943.     Private _Customization As String
  944.     Property Customization() As String
  945.         Get
  946.             Return _Customization
  947.         End Get
  948.         Set(ByVal value As String)
  949.             If value = _Customization Then Return
  950.  
  951.             Dim Data As Byte()
  952.             Dim Items As Bloom() = Colors
  953.  
  954.             Try
  955.                 Data = Convert.FromBase64String(value)
  956.                 For I As Integer = 0 To Items.Length - 1
  957.                     Items(I).Value = Color.FromArgb(BitConverter.ToInt32(Data, I * 4))
  958.                 Next
  959.             Catch
  960.                 Return
  961.             End Try
  962.  
  963.             _Customization = value
  964.  
  965.             Colors = Items
  966.             ColorHook()
  967.             Invalidate()
  968.         End Set
  969.     End Property
  970.  
  971. #End Region
  972.  
  973. #Region " Property Helpers "
  974.  
  975.     Private Sub InvalidateBitmap()
  976.         If Width = 0 OrElse Height = 0 Then Return
  977.         B = New Bitmap(Width, Height)
  978.         G = Graphics.FromImage(B)
  979.     End Sub
  980.  
  981.     Protected Function GetColor(ByVal name As String) As Color
  982.         Return Items(name)
  983.     End Function
  984.  
  985.     Protected Sub SetColor(ByVal name As String, ByVal color As Color)
  986.         If Items.ContainsKey(name) Then Items(name) = color Else Items.Add(name, color)
  987.     End Sub
  988.     Protected Sub SetColor(ByVal name As String, ByVal r As Byte, ByVal g As Byte, ByVal b As Byte)
  989.         SetColor(name, Color.FromArgb(r, g, b))
  990.     End Sub
  991.     Protected Sub SetColor(ByVal name As String, ByVal a As Byte, ByVal r As Byte, ByVal g As Byte, ByVal b As Byte)
  992.         SetColor(name, Color.FromArgb(a, r, g, b))
  993.     End Sub
  994.     Protected Sub SetColor(ByVal name As String, ByVal a As Byte, ByVal color As Color)
  995.         SetColor(name, color.FromArgb(a, color))
  996.     End Sub
  997.  
  998.     Private Sub InvalidateCustimization()
  999.         Dim M As New MemoryStream(Items.Count * 4)
  1000.  
  1001.         For Each B As Bloom In Colors
  1002.             M.Write(BitConverter.GetBytes(B.Value.ToArgb), 0, 4)
  1003.         Next
  1004.  
  1005.         M.Close()
  1006.         _Customization = Convert.ToBase64String(M.ToArray)
  1007.     End Sub
  1008.  
  1009. #End Region
  1010.  
  1011.  
  1012. #Region " User Hooks "
  1013.  
  1014.     Protected MustOverride Sub ColorHook()
  1015.     Protected MustOverride Sub PaintHook()
  1016.  
  1017. #End Region
  1018.  
  1019.  
  1020. #Region " Center Overloads "
  1021.  
  1022.     Private CenterReturn As Point
  1023.  
  1024.     Protected Function Center(ByVal r1 As Rectangle, ByVal s1 As Size) As Point
  1025.         CenterReturn = New Point((r1.Width \ 2 - s1.Width \ 2) + r1.X, (r1.Height \ 2 - s1.Height \ 2) + r1.Y)
  1026.         Return CenterReturn
  1027.     End Function
  1028.     Protected Function Center(ByVal r1 As Rectangle, ByVal r2 As Rectangle) As Point
  1029.         Return Center(r1, r2.Size)
  1030.     End Function
  1031.  
  1032.     Protected Function Center(ByVal w1 As Integer, ByVal h1 As Integer, ByVal w2 As Integer, ByVal h2 As Integer) As Point
  1033.         CenterReturn = New Point(w1 \ 2 - w2 \ 2, h1 \ 2 - h2 \ 2)
  1034.         Return CenterReturn
  1035.     End Function
  1036.  
  1037.     Protected Function Center(ByVal s1 As Size, ByVal s2 As Size) As Point
  1038.         Return Center(s1.Width, s1.Height, s2.Width, s2.Height)
  1039.     End Function
  1040.  
  1041.     Protected Function Center(ByVal r1 As Rectangle) As Point
  1042.         Return Center(ClientRectangle.Width, ClientRectangle.Height, r1.Width, r1.Height)
  1043.     End Function
  1044.     Protected Function Center(ByVal s1 As Size) As Point
  1045.         Return Center(Width, Height, s1.Width, s1.Height)
  1046.     End Function
  1047.     Protected Function Center(ByVal w1 As Integer, ByVal h1 As Integer) As Point
  1048.         Return Center(Width, Height, w1, h1)
  1049.     End Function
  1050.  
  1051. #End Region
  1052.  
  1053. #Region " Measure Overloads "
  1054.  
  1055.     Private MeasureBitmap As Bitmap
  1056.     Private MeasureGraphics As Graphics
  1057.  
  1058.     Protected Function Measure(ByVal text As String) As Size
  1059.         Return MeasureGraphics.MeasureString(text, Font, Width).ToSize
  1060.     End Function
  1061.     Protected Function Measure() As Size
  1062.         Return MeasureGraphics.MeasureString(Text, Font, Width).ToSize
  1063.     End Function
  1064.  
  1065. #End Region
  1066.  
  1067. #Region " DrawCorners Overloads "
  1068.  
  1069.     'TODO: Optimize by checking brush color
  1070.  
  1071.     Private DrawCornersBrush As SolidBrush
  1072.  
  1073.     Protected Sub DrawCorners(ByVal c1 As Color)
  1074.         DrawCorners(c1, 0, 0, Width, Height)
  1075.     End Sub
  1076.     Protected Sub DrawCorners(ByVal c1 As Color, ByVal r1 As Rectangle)
  1077.         DrawCorners(c1, r1.X, r1.Y, r1.Width, r1.Height)
  1078.     End Sub
  1079.     Protected Sub DrawCorners(ByVal c1 As Color, ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer)
  1080.         If _NoRounding Then Return
  1081.  
  1082.         If _Transparent Then
  1083.             B.SetPixel(x, y, c1)
  1084.             B.SetPixel(x + (width - 1), y, c1)
  1085.             B.SetPixel(x, y + (height - 1), c1)
  1086.             B.SetPixel(x + (width - 1), y + (height - 1), c1)
  1087.         Else
  1088.             DrawCornersBrush = New SolidBrush(c1)
  1089.             G.FillRectangle(DrawCornersBrush, x, y, 1, 1)
  1090.             G.FillRectangle(DrawCornersBrush, x + (width - 1), y, 1, 1)
  1091.             G.FillRectangle(DrawCornersBrush, x, y + (height - 1), 1, 1)
  1092.             G.FillRectangle(DrawCornersBrush, x + (width - 1), y + (height - 1), 1, 1)
  1093.         End If
  1094.     End Sub
  1095.  
  1096. #End Region
  1097.  
  1098. #Region " DrawBorders Overloads "
  1099.  
  1100.     'TODO: Remove triple overload?
  1101.  
  1102.     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)
  1103.         DrawBorders(p1, x + offset, y + offset, width - (offset * 2), height - (offset * 2))
  1104.     End Sub
  1105.     Protected Sub DrawBorders(ByVal p1 As Pen, ByVal offset As Integer)
  1106.         DrawBorders(p1, 0, 0, Width, Height, offset)
  1107.     End Sub
  1108.     Protected Sub DrawBorders(ByVal p1 As Pen, ByVal r As Rectangle, ByVal offset As Integer)
  1109.         DrawBorders(p1, r.X, r.Y, r.Width, r.Height, offset)
  1110.     End Sub
  1111.  
  1112.     Protected Sub DrawBorders(ByVal p1 As Pen, ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer)
  1113.         G.DrawRectangle(p1, x, y, width - 1, height - 1)
  1114.     End Sub
  1115.     Protected Sub DrawBorders(ByVal p1 As Pen)
  1116.         DrawBorders(p1, 0, 0, Width, Height)
  1117.     End Sub
  1118.     Protected Sub DrawBorders(ByVal p1 As Pen, ByVal r As Rectangle)
  1119.         DrawBorders(p1, r.X, r.Y, r.Width, r.Height)
  1120.     End Sub
  1121.  
  1122. #End Region
  1123.  
  1124. #Region " DrawText Overloads "
  1125.  
  1126.     'TODO: Remove triple overloads?
  1127.  
  1128.     Private DrawTextPoint As Point
  1129.     Private DrawTextSize As Size
  1130.  
  1131.     Protected Sub DrawText(ByVal b1 As Brush, ByVal a As HorizontalAlignment, ByVal x As Integer, ByVal y As Integer)
  1132.         DrawText(b1, Text, a, x, y)
  1133.     End Sub
  1134.     Protected Sub DrawText(ByVal b1 As Brush, ByVal p1 As Point)
  1135.         DrawText(b1, Text, p1.X, p1.Y)
  1136.     End Sub
  1137.     Protected Sub DrawText(ByVal b1 As Brush, ByVal x As Integer, ByVal y As Integer)
  1138.         DrawText(b1, Text, x, y)
  1139.     End Sub
  1140.  
  1141.     Protected Sub DrawText(ByVal b1 As Brush, ByVal text As String, ByVal a As HorizontalAlignment, ByVal x As Integer, ByVal y As Integer)
  1142.         If text.Length = 0 Then Return
  1143.         DrawTextSize = Measure(text)
  1144.         DrawTextPoint = Center(DrawTextSize)
  1145.  
  1146.         Select Case a
  1147.             Case HorizontalAlignment.Left
  1148.                 DrawText(b1, text, x, DrawTextPoint.Y + y)
  1149.             Case HorizontalAlignment.Center
  1150.                 DrawText(b1, text, DrawTextPoint.X + x, DrawTextPoint.Y + y)
  1151.             Case HorizontalAlignment.Right
  1152.                 DrawText(b1, text, Width - DrawTextSize.Width - x, DrawTextPoint.Y + y)
  1153.         End Select
  1154.     End Sub
  1155.     Protected Sub DrawText(ByVal b1 As Brush, ByVal text As String, ByVal p1 As Point)
  1156.         DrawText(b1, text, p1.X, p1.Y)
  1157.     End Sub
  1158.     Protected Sub DrawText(ByVal b1 As Brush, ByVal text As String, ByVal x As Integer, ByVal y As Integer)
  1159.         If text.Length = 0 Then Return
  1160.         G.DrawString(text, Font, b1, x, y)
  1161.     End Sub
  1162.  
  1163. #End Region
  1164.  
  1165. #Region " DrawImage Overloads "
  1166.  
  1167.     'TODO: Remove triple overloads?
  1168.  
  1169.     Private DrawImagePoint As Point
  1170.  
  1171.     Protected Sub DrawImage(ByVal a As HorizontalAlignment, ByVal x As Integer, ByVal y As Integer)
  1172.         DrawImage(_Image, a, x, y)
  1173.     End Sub
  1174.     Protected Sub DrawImage(ByVal p1 As Point)
  1175.         DrawImage(_Image, p1.X, p1.Y)
  1176.     End Sub
  1177.     Protected Sub DrawImage(ByVal x As Integer, ByVal y As Integer)
  1178.         DrawImage(_Image, x, y)
  1179.     End Sub
  1180.  
  1181.     Protected Sub DrawImage(ByVal image As Image, ByVal a As HorizontalAlignment, ByVal x As Integer, ByVal y As Integer)
  1182.         If image Is Nothing Then Return
  1183.         DrawImagePoint = Center(image.Size)
  1184.  
  1185.         Select Case a
  1186.             Case HorizontalAlignment.Left
  1187.                 DrawImage(image, x, DrawImagePoint.Y + y)
  1188.             Case HorizontalAlignment.Center
  1189.                 DrawImage(image, DrawImagePoint.X + x, DrawImagePoint.Y + y)
  1190.             Case HorizontalAlignment.Right
  1191.                 DrawImage(image, Width - image.Width - x, DrawImagePoint.Y + y)
  1192.         End Select
  1193.     End Sub
  1194.     Protected Sub DrawImage(ByVal image As Image, ByVal p1 As Point)
  1195.         DrawImage(image, p1.X, p1.Y)
  1196.     End Sub
  1197.     Protected Sub DrawImage(ByVal image As Image, ByVal x As Integer, ByVal y As Integer)
  1198.         If image Is Nothing Then Return
  1199.         G.DrawImage(image, x, y, image.Width, image.Height)
  1200.     End Sub
  1201.  
  1202. #End Region
  1203.  
  1204. #Region " DrawGradient Overloads "
  1205.  
  1206.     'TODO: Remove triple overload?
  1207.  
  1208.     Private DrawGradientBrush As LinearGradientBrush
  1209.     Private DrawGradientRectangle As Rectangle
  1210.  
  1211.     Protected Sub DrawGradient(ByVal blend As ColorBlend, ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer)
  1212.         DrawGradient(blend, x, y, width, height, 90S)
  1213.     End Sub
  1214.     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)
  1215.         DrawGradient(c1, c2, x, y, width, height, 90S)
  1216.     End Sub
  1217.  
  1218.     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)
  1219.         DrawGradientRectangle = New Rectangle(x, y, width, height)
  1220.         DrawGradient(blend, DrawGradientRectangle, angle)
  1221.     End Sub
  1222.     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)
  1223.         DrawGradientRectangle = New Rectangle(x, y, width, height)
  1224.         DrawGradient(c1, c2, DrawGradientRectangle, angle)
  1225.     End Sub
  1226.  
  1227.     Protected Sub DrawGradient(ByVal blend As ColorBlend, ByVal r As Rectangle, ByVal angle As Single)
  1228.         DrawGradientBrush = New LinearGradientBrush(r, Color.Empty, Color.Empty, angle)
  1229.         DrawGradientBrush.InterpolationColors = blend
  1230.         G.FillRectangle(DrawGradientBrush, r)
  1231.     End Sub
  1232.     Protected Sub DrawGradient(ByVal c1 As Color, ByVal c2 As Color, ByVal r As Rectangle, ByVal angle As Single)
  1233.         DrawGradientBrush = New LinearGradientBrush(r, c1, c2, angle)
  1234.         G.FillRectangle(DrawGradientBrush, r)
  1235.     End Sub
  1236.  
  1237. #End Region
  1238.  
  1239. End Class
  1240.  
  1241. Class ComplexTheme
  1242.     Inherits ThemeContainer151
  1243.     Protected Overrides Sub ColorHook()
  1244.     End Sub
  1245.     Sub New()
  1246.         MoveHeight = 28
  1247.     End Sub
  1248.  
  1249.     Protected Overrides Sub PaintHook()
  1250.         Dim hb2 As New Drawing2D.HatchBrush(Drawing2D.HatchStyle.Trellis, Color.FromArgb(15, 15, 15))
  1251.         Dim sb1 As New SolidBrush(Color.LightGray)
  1252.         Dim sb3 As New SolidBrush(Color.White)
  1253.         Dim sb2 As New SolidBrush(Color.FromArgb(35, 35, 35))
  1254.         G.Clear(Color.LightGray)
  1255.         G.DrawRectangle(New Pen(New SolidBrush(Color.LightGray)), New Rectangle(0, 0, Width, 28))
  1256.         G.FillRectangle(sb1, New Rectangle(0, 0, Width, 28))
  1257.         G.DrawString(Text, Font, Brushes.Black, New Point(5, 8))
  1258.         Dim SubFont As Font = New Font(DefaultFont.FontFamily, Font.Size - 1)
  1259.         G.DrawRectangle(Pens.LightGray, New Rectangle(0, 0, Width - 1, Height - 1))
  1260.         G.FillRectangle(sb3, New Rectangle(8, 28, Width - 16, Height - 35))
  1261.         DrawCorners(Color.White)
  1262.     End Sub
  1263. End Class
  1264.  
  1265. Class ComplexButton
  1266.     Inherits ThemeControl151
  1267.     Protected Overrides Sub ColorHook()
  1268.  
  1269.     End Sub
  1270.     Private B1 As Brush
  1271.     Private B2 As Brush
  1272.     Private B3 As Brush
  1273.     Protected Overrides Sub PaintHook()
  1274.         B1 = New SolidBrush(Color.FromArgb(50, Color.Gray))
  1275.         B2 = New SolidBrush(Color.FromArgb(50, Color.LightGray))
  1276.         B3 = New SolidBrush(Color.FromArgb(50, Color.DarkGray))
  1277.         G.Clear(BackColor)
  1278.         Select Case State
  1279.             Case MouseState.None
  1280.                 G.FillRectangle(B1, ClientRectangle)
  1281.             Case MouseState.Over
  1282.                 G.FillRectangle(B2, ClientRectangle)
  1283.             Case MouseState.Down
  1284.                 G.FillRectangle(B3, ClientRectangle)
  1285.         End Select
  1286.  
  1287.         G.DrawString(Text, Font, Brushes.Black, New Point(CInt((Me.Width / 2) - (Measure(Text).Width / 2)), CInt((Me.Height / 2) - (Measure(Text).Height / 2))))
  1288.  
  1289.         G.DrawRectangle(Pens.LightGray, New Rectangle(0, 0, Width - 1, Height - 1))
  1290.         DrawCorners(Color.White)
  1291.     End Sub
  1292. End Class
  1293. Class ComplexTopButton
  1294.     Inherits ThemeControl151
  1295.     Protected Overrides Sub ColorHook()
  1296.  
  1297.     End Sub
  1298.     Private B1 As Brush
  1299.     Private B2 As Brush
  1300.     Private B3 As Brush
  1301.     Protected Overrides Sub PaintHook()
  1302.         B1 = New SolidBrush(Color.FromArgb(50, Color.Gray))
  1303.         B2 = New SolidBrush(Color.FromArgb(50, Color.LightGray))
  1304.         B3 = New SolidBrush(Color.FromArgb(50, Color.DarkGray))
  1305.         G.Clear(BackColor)
  1306.         Select Case State
  1307.             Case MouseState.None
  1308.                 G.FillRectangle(B1, ClientRectangle)
  1309.             Case MouseState.Over
  1310.                 G.FillRectangle(B2, ClientRectangle)
  1311.             Case MouseState.Down
  1312.                 G.FillRectangle(B3, ClientRectangle)
  1313.         End Select
  1314.  
  1315.         G.DrawString(Text, Font, Brushes.Black, New Point(CInt((Me.Width / 2) - (Measure(Text).Width / 2)), CInt((Me.Height / 2) - (Measure(Text).Height / 2))))
  1316.  
  1317.         G.DrawRectangle(Pens.LightGray, New Rectangle(0, 0, Width - 1, Height - 1))
  1318.     End Sub
  1319. End Class
  1320.  
  1321. Class ComplexProgressBar
  1322.     Inherits ThemeControl151
  1323.     Private _Maximum As Integer = 100
  1324.     Public Property Maximum() As Integer
  1325.         Get
  1326.             Return _Maximum
  1327.         End Get
  1328.         Set(ByVal value As Integer)
  1329.             If value < 1 Then value = 1
  1330.             If value < _Value Then _Value = value
  1331.             _Maximum = value
  1332.             Invalidate()
  1333.         End Set
  1334.     End Property
  1335.  
  1336.     Private _Value As Integer = 50
  1337.     Public Property Value() As Integer
  1338.         Get
  1339.             Return _Value
  1340.         End Get
  1341.         Set(ByVal value As Integer)
  1342.             If value > _Maximum Then value = _Maximum
  1343.             _Value = value
  1344.             Invalidate()
  1345.         End Set
  1346.     End Property
  1347.  
  1348.     Private C2 As Color
  1349.     Private P1 As Pen
  1350.     Private B1 As Brush
  1351.     Private B2 As Brush
  1352.     Private B3 As Brush
  1353.     Sub New()
  1354.         Size = New Size(75, 18)
  1355.     End Sub
  1356.     Protected Overrides Sub ColorHook()
  1357.         C2 = Color.LightGray
  1358.         P1 = Pens.LightGray
  1359.     End Sub
  1360.  
  1361.     Protected Overrides Sub PaintHook()
  1362.         B1 = New SolidBrush(Color.FromArgb(50, Color.Gray))
  1363.         B2 = New SolidBrush(Color.FromArgb(50, Color.LightGray))
  1364.         B3 = New SolidBrush(Color.FromArgb(50, Color.DarkGray))
  1365.         G.Clear(C2)
  1366.         If (_Value > 0) Then
  1367.             G.FillRectangle(B3, 0, 0, CInt((_Value / _Maximum) * Width), Height)
  1368.         End If
  1369.         DrawBorders(P1, 0, 0, Width, Height)
  1370.         DrawCorners(Color.White)
  1371.     End Sub
  1372. End Class
  1373.  
  1374. Class ComplexGroupBox
  1375.     Inherits ThemeContainer151
  1376.     Private C1 As Color
  1377.     Private C2 As Color
  1378.     Private C3 As Color
  1379.     Private P1 As Pen
  1380.     Private B1 As Brush
  1381.     Private B2 As Brush
  1382.     Private B3 As Brush
  1383.     Private B0 As Brush
  1384.     Private B8 As Brush
  1385.     Private HB1 As Brush
  1386.     Sub New()
  1387.         ControlMode = True
  1388.         Size = New Size(205, 95)
  1389.     End Sub
  1390.     Protected Overrides Sub ColorHook()
  1391.         C1 = Color.White
  1392.         C2 = Color.FromArgb(50, 50, 50)
  1393.         C3 = Color.FromArgb(0, 0, 0)
  1394.         P1 = Pens.LightGray
  1395.         B0 = New SolidBrush(Color.FromArgb(60, Color.White))
  1396.         B8 = New SolidBrush(Color.Black)
  1397.         B2 = New SolidBrush(Color.White)
  1398.     End Sub
  1399.  
  1400.     Protected Overrides Sub PaintHook()
  1401.         B1 = New SolidBrush(Color.FromArgb(50, Color.Gray))
  1402.         B2 = New SolidBrush(Color.FromArgb(50, Color.LightGray))
  1403.         B3 = New SolidBrush(Color.FromArgb(50, Color.DarkGray))
  1404.         G.Clear(C1)
  1405.         G.FillRectangle(B0, 0, 0, Width, Height)
  1406.         G.FillRectangle(B0, 0, 0, Width, 15)
  1407.         G.DrawRectangle(P1, 0, 15, Width - 1, CInt(Height - 16))
  1408.         G.FillRectangle(B3, 0, 15, Width, 20)
  1409.         G.FillRectangle(B3, 0, 15, Width, 20)
  1410.         DrawText(B8, HorizontalAlignment.Left, 3, 13)
  1411.         DrawCorners(Color.White)
  1412.     End Sub
  1413. End Class
  1414. Enum MouseState As Byte
  1415.     None = 0
  1416.     Over = 1
  1417.     Down = 2
  1418.     Block = 3
  1419. End Enum
  1420.  
  1421. Class Bloom
  1422.  
  1423.     Private _Name As String
  1424.     Property Name() As String
  1425.         Get
  1426.             Return _Name
  1427.         End Get
  1428.         Set(ByVal value As String)
  1429.             _Name = value
  1430.         End Set
  1431.     End Property
  1432.  
  1433.     Private _Value As Color
  1434.     Property Value() As Color
  1435.         Get
  1436.             Return _Value
  1437.         End Get
  1438.         Set(ByVal value As Color)
  1439.             _Value = value
  1440.         End Set
  1441.     End Property
  1442.  
  1443.     Sub New()
  1444.     End Sub
  1445.  
  1446.     Sub New(ByVal name As String, ByVal value As Color)
  1447.         _Name = name
  1448.         _Value = value
  1449.     End Sub
  1450. End Class
Advertisement
Add Comment
Please, Sign In to add comment