Advertisement
benito

Untitled

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