Advertisement
Guest User

Genuine Theme by Aeonhack

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