Advertisement
john_oneill

[VB.NET] My Theme (1/4 Done)

Dec 15th, 2011
1,571
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 17.07 KB | None | 0 0
  1. '''''''''''''''''''''''''''''''
  2. 'Theme Base                   '
  3. 'Creator: Aeonhack            '
  4. 'Date: 4/23/2011              '
  5. 'Site: www.elitevs.net        '
  6. 'Version: 1.4                 '
  7. '''''''''''''''''''''''''''''''
  8. 'Theme Maker                  '
  9. 'Creator: John                '
  10. 'Date: 15/12/2011             '
  11. 'Site: www.FiveStarGamerz.com '
  12. 'Version: 1.0                 '
  13. '''''''''''''''''''''''''''''''
  14.  
  15. Imports System.Drawing.Drawing2D
  16. Imports System.ComponentModel
  17. Imports System.Runtime.InteropServices
  18.  
  19. MustInherit Class Theme
  20.     Inherits ContainerControl
  21.  
  22. #Region " Initialization "
  23.  
  24.     Protected G As Graphics
  25.     Sub New()
  26.         SetStyle(DirectCast(139270, ControlStyles), True)
  27.     End Sub
  28.  
  29.     Private ParentIsForm As Boolean
  30.     Protected Overrides Sub OnHandleCreated(ByVal e As EventArgs)
  31.         Dock = DockStyle.Fill
  32.         ParentIsForm = TypeOf Parent Is Form
  33.         If ParentIsForm Then
  34.             If Not _TransparencyKey = Color.Empty Then ParentForm.TransparencyKey = _TransparencyKey
  35.             ParentForm.FormBorderStyle = FormBorderStyle.None
  36.         End If
  37.         MyBase.OnHandleCreated(e)
  38.     End Sub
  39.  
  40.     Overrides Property Text As String
  41.         Get
  42.             Return MyBase.Text
  43.         End Get
  44.         Set(ByVal v As String)
  45.             MyBase.Text = v
  46.             Invalidate()
  47.         End Set
  48.     End Property
  49. #End Region
  50.  
  51. #Region " Sizing and Movement "
  52.  
  53.     Private _Resizable As Boolean = True
  54.     Property Resizable() As Boolean
  55.         Get
  56.             Return _Resizable
  57.         End Get
  58.         Set(ByVal value As Boolean)
  59.             _Resizable = value
  60.         End Set
  61.     End Property
  62.  
  63.     Private _MoveHeight As Integer = 24
  64.     Property MoveHeight() As Integer
  65.         Get
  66.             Return _MoveHeight
  67.         End Get
  68.         Set(ByVal v As Integer)
  69.             _MoveHeight = v
  70.             Header = New Rectangle(7, 7, Width - 14, _MoveHeight - 7)
  71.         End Set
  72.     End Property
  73.  
  74.     Private Flag As IntPtr
  75.     Protected Overrides Sub OnMouseDown(ByVal e As MouseEventArgs)
  76.         If Not e.Button = MouseButtons.Left Then Return
  77.         If ParentIsForm Then If ParentForm.WindowState = FormWindowState.Maximized Then Return
  78.  
  79.         If Header.Contains(e.Location) Then
  80.             Flag = New IntPtr(2)
  81.         ElseIf Current.Position = 0 Or Not _Resizable Then
  82.             Return
  83.         Else
  84.             Flag = New IntPtr(Current.Position)
  85.         End If
  86.  
  87.         Capture = False
  88.         DefWndProc(Message.Create(Parent.Handle, 161, Flag, Nothing))
  89.  
  90.         MyBase.OnMouseDown(e)
  91.     End Sub
  92.  
  93.     Private Structure Pointer
  94.         ReadOnly Cursor As Cursor, Position As Byte
  95.         Sub New(ByVal c As Cursor, ByVal p As Byte)
  96.             Cursor = c
  97.             Position = p
  98.         End Sub
  99.     End Structure
  100.  
  101.     Private F1, F2, F3, F4 As Boolean, PTC As Point
  102.     Private Function GetPointer() As Pointer
  103.         PTC = PointToClient(MousePosition)
  104.         F1 = PTC.X < 7
  105.         F2 = PTC.X > Width - 7
  106.         F3 = PTC.Y < 7
  107.         F4 = PTC.Y > Height - 7
  108.  
  109.         If F1 And F3 Then Return New Pointer(Cursors.SizeNWSE, 13)
  110.         If F1 And F4 Then Return New Pointer(Cursors.SizeNESW, 16)
  111.         If F2 And F3 Then Return New Pointer(Cursors.SizeNESW, 14)
  112.         If F2 And F4 Then Return New Pointer(Cursors.SizeNWSE, 17)
  113.         If F1 Then Return New Pointer(Cursors.SizeWE, 10)
  114.         If F2 Then Return New Pointer(Cursors.SizeWE, 11)
  115.         If F3 Then Return New Pointer(Cursors.SizeNS, 12)
  116.         If F4 Then Return New Pointer(Cursors.SizeNS, 15)
  117.         Return New Pointer(Cursors.Default, 0)
  118.     End Function
  119.  
  120.     Private Current, Pending As Pointer
  121.     Private Sub SetCurrent()
  122.         Pending = GetPointer()
  123.         If Current.Position = Pending.Position Then Return
  124.         Current = GetPointer()
  125.         Cursor = Current.Cursor
  126.     End Sub
  127.  
  128.     Protected Overrides Sub OnMouseMove(ByVal e As MouseEventArgs)
  129.         If _Resizable Then SetCurrent()
  130.         MyBase.OnMouseMove(e)
  131.     End Sub
  132.  
  133.     Protected Header As Rectangle
  134.     Protected Overrides Sub OnSizeChanged(ByVal e As EventArgs)
  135.         If Width = 0 OrElse Height = 0 Then Return
  136.         Header = New Rectangle(7, 7, Width - 14, _MoveHeight - 7)
  137.         Invalidate()
  138.         MyBase.OnSizeChanged(e)
  139.     End Sub
  140.  
  141. #End Region
  142.  
  143. #Region " Convienence "
  144.  
  145.     MustOverride Sub PaintHook()
  146.     Protected NotOverridable Overrides Sub OnPaint(ByVal e As PaintEventArgs)
  147.         If Width = 0 OrElse Height = 0 Then Return
  148.         G = e.Graphics
  149.         PaintHook()
  150.     End Sub
  151.  
  152.     Private _TransparencyKey As Color
  153.     Property TransparencyKey() As Color
  154.         Get
  155.             Return _TransparencyKey
  156.         End Get
  157.         Set(ByVal v As Color)
  158.             _TransparencyKey = v
  159.             Invalidate()
  160.         End Set
  161.     End Property
  162.  
  163.     Private _Image As Image
  164.     Property Image() As Image
  165.         Get
  166.             Return _Image
  167.         End Get
  168.         Set(ByVal value As Image)
  169.             _Image = value
  170.             Invalidate()
  171.         End Set
  172.     End Property
  173.     ReadOnly Property ImageWidth() As Integer
  174.         Get
  175.             If _Image Is Nothing Then Return 0
  176.             Return _Image.Width
  177.         End Get
  178.     End Property
  179.  
  180.     Private _Size As Size
  181.     Private _Rectangle As Rectangle
  182.     Private _Gradient As LinearGradientBrush
  183.     Private _Brush As SolidBrush
  184.  
  185.     Protected Sub DrawCorners(ByVal c As Color, ByVal rect As Rectangle)
  186.         _Brush = New SolidBrush(c)
  187.         G.FillRectangle(_Brush, rect.X, rect.Y, 1, 1)
  188.         G.FillRectangle(_Brush, rect.X + (rect.Width - 1), rect.Y, 1, 1)
  189.         G.FillRectangle(_Brush, rect.X, rect.Y + (rect.Height - 1), 1, 1)
  190.         G.FillRectangle(_Brush, rect.X + (rect.Width - 1), rect.Y + (rect.Height - 1), 1, 1)
  191.     End Sub
  192.  
  193.     Protected Sub DrawBorders(ByVal p1 As Pen, ByVal p2 As Pen, ByVal rect As Rectangle)
  194.         G.DrawRectangle(p1, rect.X, rect.Y, rect.Width - 1, rect.Height - 1)
  195.         G.DrawRectangle(p2, rect.X + 1, rect.Y + 1, rect.Width - 3, rect.Height - 3)
  196.     End Sub
  197.  
  198.     Protected Sub DrawText(ByVal a As HorizontalAlignment, ByVal c As Color, ByVal x As Integer)
  199.         DrawText(a, c, x, 0)
  200.     End Sub
  201.     Protected Sub DrawText(ByVal a As HorizontalAlignment, ByVal c As Color, ByVal x As Integer, ByVal y As Integer)
  202.         If String.IsNullOrEmpty(Text) Then Return
  203.         _Size = G.MeasureString(Text, Font).ToSize
  204.         _Brush = New SolidBrush(c)
  205.  
  206.         Select Case a
  207.             Case HorizontalAlignment.Left
  208.                 G.DrawString(Text, Font, _Brush, x, _MoveHeight \ 2 - _Size.Height \ 2 + y)
  209.             Case HorizontalAlignment.Right
  210.                 G.DrawString(Text, Font, _Brush, Width - _Size.Width - x, _MoveHeight \ 2 - _Size.Height \ 2 + y)
  211.             Case HorizontalAlignment.Center
  212.                 G.DrawString(Text, Font, _Brush, Width \ 2 - _Size.Width \ 2 + x, _MoveHeight \ 2 - _Size.Height \ 2 + y)
  213.         End Select
  214.     End Sub
  215.  
  216.     Protected Sub DrawIcon(ByVal a As HorizontalAlignment, ByVal x As Integer)
  217.         DrawIcon(a, x, 0)
  218.     End Sub
  219.     Protected Sub DrawIcon(ByVal a As HorizontalAlignment, ByVal x As Integer, ByVal y As Integer)
  220.         If _Image Is Nothing Then Return
  221.         Select Case a
  222.             Case HorizontalAlignment.Left
  223.                 G.DrawImage(_Image, x, _MoveHeight \ 2 - _Image.Height \ 2 + y)
  224.             Case HorizontalAlignment.Right
  225.                 G.DrawImage(_Image, Width - _Image.Width - x, _MoveHeight \ 2 - _Image.Height \ 2 + y)
  226.             Case HorizontalAlignment.Center
  227.                 G.DrawImage(_Image, Width \ 2 - _Image.Width \ 2, _MoveHeight \ 2 - _Image.Height \ 2)
  228.         End Select
  229.     End Sub
  230.  
  231.     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)
  232.         _Rectangle = New Rectangle(x, y, width, height)
  233.         _Gradient = New LinearGradientBrush(_Rectangle, c1, c2, angle)
  234.         G.FillRectangle(_Gradient, _Rectangle)
  235.     End Sub
  236.  
  237. #End Region
  238.  
  239. End Class
  240. MustInherit Class ThemeControl
  241.     Inherits Control
  242.  
  243. #Region " Initialization "
  244.  
  245.     Protected G As Graphics, B As Bitmap
  246.     Sub New()
  247.         SetStyle(DirectCast(139270, ControlStyles), True)
  248.         B = New Bitmap(1, 1)
  249.         G = Graphics.FromImage(B)
  250.     End Sub
  251.  
  252.     Sub AllowTransparent()
  253.         SetStyle(ControlStyles.Opaque, False)
  254.         SetStyle(ControlStyles.SupportsTransparentBackColor, True)
  255.     End Sub
  256.  
  257.     Overrides Property Text As String
  258.         Get
  259.             Return MyBase.Text
  260.         End Get
  261.         Set(ByVal v As String)
  262.             MyBase.Text = v
  263.             Invalidate()
  264.         End Set
  265.     End Property
  266. #End Region
  267.  
  268. #Region " Mouse Handling "
  269.  
  270.     Protected Enum State As Byte
  271.         MouseNone = 0
  272.         MouseOver = 1
  273.         MouseDown = 2
  274.     End Enum
  275.  
  276.     Protected MouseState As State
  277.     Protected Overrides Sub OnMouseLeave(ByVal e As EventArgs)
  278.         ChangeMouseState(State.MouseNone)
  279.         MyBase.OnMouseLeave(e)
  280.     End Sub
  281.     Protected Overrides Sub OnMouseEnter(ByVal e As EventArgs)
  282.         ChangeMouseState(State.MouseOver)
  283.         MyBase.OnMouseEnter(e)
  284.     End Sub
  285.     Protected Overrides Sub OnMouseUp(ByVal e As MouseEventArgs)
  286.         ChangeMouseState(State.MouseOver)
  287.         MyBase.OnMouseUp(e)
  288.     End Sub
  289.     Protected Overrides Sub OnMouseDown(ByVal e As MouseEventArgs)
  290.         If e.Button = MouseButtons.Left Then ChangeMouseState(State.MouseDown)
  291.         MyBase.OnMouseDown(e)
  292.     End Sub
  293.  
  294.     Private Sub ChangeMouseState(ByVal e As State)
  295.         MouseState = e
  296.         Invalidate()
  297.     End Sub
  298.  
  299. #End Region
  300.  
  301. #Region " Convienence "
  302.  
  303.     MustOverride Sub PaintHook()
  304.     Protected NotOverridable Overrides Sub OnPaint(ByVal e As PaintEventArgs)
  305.         If Width = 0 OrElse Height = 0 Then Return
  306.         PaintHook()
  307.         e.Graphics.DrawImage(B, 0, 0)
  308.     End Sub
  309.  
  310.     Protected Overrides Sub OnSizeChanged(ByVal e As EventArgs)
  311.         If Not Width = 0 AndAlso Not Height = 0 Then
  312.             B = New Bitmap(Width, Height)
  313.             G = Graphics.FromImage(B)
  314.             Invalidate()
  315.         End If
  316.         MyBase.OnSizeChanged(e)
  317.     End Sub
  318.  
  319.     Private _NoRounding As Boolean
  320.     Property NoRounding() As Boolean
  321.         Get
  322.             Return _NoRounding
  323.         End Get
  324.         Set(ByVal v As Boolean)
  325.             _NoRounding = v
  326.             Invalidate()
  327.         End Set
  328.     End Property
  329.  
  330.     Private _Image As Image
  331.     Property Image() As Image
  332.         Get
  333.             Return _Image
  334.         End Get
  335.         Set(ByVal value As Image)
  336.             _Image = value
  337.             Invalidate()
  338.         End Set
  339.     End Property
  340.     ReadOnly Property ImageWidth() As Integer
  341.         Get
  342.             If _Image Is Nothing Then Return 0
  343.             Return _Image.Width
  344.         End Get
  345.     End Property
  346.     ReadOnly Property ImageTop() As Integer
  347.         Get
  348.             If _Image Is Nothing Then Return 0
  349.             Return Height \ 2 - _Image.Height \ 2
  350.         End Get
  351.     End Property
  352.  
  353.     Private _Size As Size
  354.     Private _Rectangle As Rectangle
  355.     Private _Gradient As LinearGradientBrush
  356.     Private _Brush As SolidBrush
  357.  
  358.     Protected Sub DrawCorners(ByVal c As Color, ByVal rect As Rectangle)
  359.         If _NoRounding Then Return
  360.  
  361.         B.SetPixel(rect.X, rect.Y, c)
  362.         B.SetPixel(rect.X + (rect.Width - 1), rect.Y, c)
  363.         B.SetPixel(rect.X, rect.Y + (rect.Height - 1), c)
  364.         B.SetPixel(rect.X + (rect.Width - 1), rect.Y + (rect.Height - 1), c)
  365.     End Sub
  366.  
  367.     Protected Sub DrawBorders(ByVal p1 As Pen, ByVal p2 As Pen, ByVal rect As Rectangle)
  368.         G.DrawRectangle(p1, rect.X, rect.Y, rect.Width - 1, rect.Height - 1)
  369.         G.DrawRectangle(p2, rect.X + 1, rect.Y + 1, rect.Width - 3, rect.Height - 3)
  370.     End Sub
  371.  
  372.     Protected Sub DrawText(ByVal a As HorizontalAlignment, ByVal c As Color, ByVal x As Integer)
  373.         DrawText(a, c, x, 0)
  374.     End Sub
  375.     Protected Sub DrawText(ByVal a As HorizontalAlignment, ByVal c As Color, ByVal x As Integer, ByVal y As Integer)
  376.         If String.IsNullOrEmpty(Text) Then Return
  377.         _Size = G.MeasureString(Text, Font).ToSize
  378.         _Brush = New SolidBrush(c)
  379.  
  380.         Select Case a
  381.             Case HorizontalAlignment.Left
  382.                 G.DrawString(Text, Font, _Brush, x, Height \ 2 - _Size.Height \ 2 + y)
  383.             Case HorizontalAlignment.Right
  384.                 G.DrawString(Text, Font, _Brush, Width - _Size.Width - x, Height \ 2 - _Size.Height \ 2 + y)
  385.             Case HorizontalAlignment.Center
  386.                 G.DrawString(Text, Font, _Brush, Width \ 2 - _Size.Width \ 2 + x, Height \ 2 - _Size.Height \ 2 + y)
  387.         End Select
  388.     End Sub
  389.  
  390.     Protected Sub DrawIcon(ByVal a As HorizontalAlignment, ByVal x As Integer)
  391.         DrawIcon(a, x, 0)
  392.     End Sub
  393.     Protected Sub DrawIcon(ByVal a As HorizontalAlignment, ByVal x As Integer, ByVal y As Integer)
  394.         If _Image Is Nothing Then Return
  395.         Select Case a
  396.             Case HorizontalAlignment.Left
  397.                 G.DrawImage(_Image, x, Height \ 2 - _Image.Height \ 2 + y)
  398.             Case HorizontalAlignment.Right
  399.                 G.DrawImage(_Image, Width - _Image.Width - x, Height \ 2 - _Image.Height \ 2 + y)
  400.             Case HorizontalAlignment.Center
  401.                 G.DrawImage(_Image, Width \ 2 - _Image.Width \ 2, Height \ 2 - _Image.Height \ 2)
  402.         End Select
  403.     End Sub
  404.  
  405.     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)
  406.         _Rectangle = New Rectangle(x, y, width, height)
  407.         _Gradient = New LinearGradientBrush(_Rectangle, c1, c2, angle)
  408.         G.FillRectangle(_Gradient, _Rectangle)
  409.     End Sub
  410. #End Region
  411.  
  412. End Class
  413. MustInherit Class ThemeContainerControl
  414.     Inherits ContainerControl
  415.  
  416. #Region " Initialization "
  417.  
  418.     Protected G As Graphics, B As Bitmap
  419.     Sub New()
  420.         SetStyle(DirectCast(139270, ControlStyles), True)
  421.         B = New Bitmap(1, 1)
  422.         G = Graphics.FromImage(B)
  423.     End Sub
  424.  
  425.     Sub AllowTransparent()
  426.         SetStyle(ControlStyles.Opaque, False)
  427.         SetStyle(ControlStyles.SupportsTransparentBackColor, True)
  428.     End Sub
  429.  
  430. #End Region
  431.  
  432. #Region " Convienence "
  433.  
  434.     MustOverride Sub PaintHook()
  435.     Protected NotOverridable Overrides Sub OnPaint(ByVal e As PaintEventArgs)
  436.         If Width = 0 OrElse Height = 0 Then Return
  437.         PaintHook()
  438.         e.Graphics.DrawImage(B, 0, 0)
  439.     End Sub
  440.  
  441.     Protected Overrides Sub OnSizeChanged(ByVal e As EventArgs)
  442.         If Not Width = 0 AndAlso Not Height = 0 Then
  443.             B = New Bitmap(Width, Height)
  444.             G = Graphics.FromImage(B)
  445.             Invalidate()
  446.         End If
  447.         MyBase.OnSizeChanged(e)
  448.     End Sub
  449.  
  450.     Private _NoRounding As Boolean
  451.     Property NoRounding() As Boolean
  452.         Get
  453.             Return _NoRounding
  454.         End Get
  455.         Set(ByVal v As Boolean)
  456.             _NoRounding = v
  457.             Invalidate()
  458.         End Set
  459.     End Property
  460.  
  461.     Private _Rectangle As Rectangle
  462.     Private _Gradient As LinearGradientBrush
  463.  
  464.     Protected Sub DrawCorners(ByVal c As Color, ByVal rect As Rectangle)
  465.         If _NoRounding Then Return
  466.         B.SetPixel(rect.X, rect.Y, c)
  467.         B.SetPixel(rect.X + (rect.Width - 1), rect.Y, c)
  468.         B.SetPixel(rect.X, rect.Y + (rect.Height - 1), c)
  469.         B.SetPixel(rect.X + (rect.Width - 1), rect.Y + (rect.Height - 1), c)
  470.     End Sub
  471.  
  472.     Protected Sub DrawBorders(ByVal p1 As Pen, ByVal p2 As Pen, ByVal rect As Rectangle)
  473.         G.DrawRectangle(p1, rect.X, rect.Y, rect.Width - 1, rect.Height - 1)
  474.         G.DrawRectangle(p2, rect.X + 1, rect.Y + 1, rect.Width - 3, rect.Height - 3)
  475.     End Sub
  476.  
  477.     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)
  478.         _Rectangle = New Rectangle(x, y, width, height)
  479.         _Gradient = New LinearGradientBrush(_Rectangle, c1, c2, angle)
  480.         G.FillRectangle(_Gradient, _Rectangle)
  481.     End Sub
  482. #End Region
  483.  
  484. End Class
  485.  
  486.  
  487. Class Theme1
  488.     Inherits Theme
  489.  
  490.     Sub New()
  491.         BackColor = Color.Gray
  492.         MoveHeight = 20
  493.         TransparencyKey = Color.Fuchsia
  494.     End Sub
  495.  
  496.     Public Overrides Sub PaintHook()
  497.         G.Clear(BackColor)
  498.  
  499.  
  500.         DrawGradient(Color.LightGray, Color.Gray, 0, 0, Width, 20, 90S)
  501.  
  502.         G.DrawLine(Pens.Black, 0, 20, Width, 20)
  503.  
  504.         DrawBorders(Pens.Black, Pens.DarkGray, ClientRectangle)
  505.         DrawCorners(Color.Fuchsia, ClientRectangle)
  506.     End Sub
  507. End Class
  508. Class ThemeButton1
  509.     Inherits ThemeControl
  510.  
  511.     Public Overrides Sub PaintHook()
  512.  
  513.  
  514.         If MouseState = State.MouseNone Then
  515.             G.Clear(Color.Gray)
  516.         Else
  517.             G.Clear(Color.DarkGray)
  518.         End If
  519.  
  520.         DrawText(HorizontalAlignment.Center, Color.Black, 0)
  521.  
  522.         DrawBorders(Pens.Black, Pens.DarkGray, ClientRectangle)
  523.         DrawCorners(BackColor, ClientRectangle)
  524.  
  525.     End Sub
  526. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement