Guest User

ProperTheme

a guest
Dec 27th, 2014
273
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Imports System.Drawing.Drawing2D
  2. Public Class Theme : Inherits ContainerControl
  3.     Private ismemaxed As Boolean = False, Cap As Boolean = False, MousePoint As New Point(0, 0), MoveHeight% = 30,closebuttonhover As Boolean = False, minibuttonhover As Boolean = False, maxibuttonhover As Boolean = False
  4.     Sub New()
  5.         SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.UserPaint Or ControlStyles.ResizeRedraw Or ControlStyles.OptimizedDoubleBuffer, True)
  6.         DoubleBuffered = True
  7.         Me.Font = New Font("Segoe UI", 12)
  8.     End Sub
  9.     <DebuggerNonUserCode> _
  10.     Protected Overrides Sub OnCreateControl()
  11.         MyBase.OnCreateControl()
  12.         ParentForm.FormBorderStyle = FormBorderStyle.None
  13.         Select Case Debugger.IsAttached
  14.             'Blend in with Visual Studio background when you are debugging.
  15.            Case True : ParentForm.TransparencyKey = Color.FromArgb(25, 25, 25) : ParentForm.BackColor = Color.FromArgb(25, 25, 25)
  16.             Case False : ParentForm.TransparencyKey = Color.FromArgb(246, 246, 246) : ParentForm.BackColor = Color.FromArgb(246, 246, 246)
  17.         End Select
  18.         ParentForm.FindForm.StartPosition = FormStartPosition.CenterScreen
  19.         Invalidate()
  20.     End Sub
  21.     <DebuggerStepThrough> _
  22.     Private Sub Theme_Resize(sender As Object, e As EventArgs) Handles Me.Resize
  23.         Try
  24.             If ismemaxed = False Then
  25.                 Me.Location = New Point(0, 0)
  26.                 ParentForm.Size = Me.Size
  27.             Else
  28.                 Me.Size = ParentForm.Size
  29.             End If
  30.         Catch ex As Exception
  31.  
  32.         End Try
  33.  
  34.  
  35.     End Sub
  36.     Protected Overrides Sub OnMouseDown(e As MouseEventArgs)
  37.         MyBase.OnMouseDown(e)
  38.         Select Case True
  39.             'The close button
  40.            Case e.Button = Windows.Forms.MouseButtons.Left And New Rectangle(Me.Width - 30, 5, 20, 20).Contains(e.Location) : ParentForm.Close() : Application.Exit()
  41.                 'maximize
  42.            Case e.Button = Windows.Forms.MouseButtons.Left And New Rectangle(Me.Width - 55, 5, 20, 20).Contains(e.Location): If ismemaxed Then : ismemaxed = False : Me.ParentForm.WindowState = FormWindowState.Normal : Else : ismemaxed = True : Me.ParentForm.WindowState = FormWindowState.Maximized : End If : Me.Size = ParentForm.Size
  43.                 'minimize
  44.            Case e.Button = Windows.Forms.MouseButtons.Left And New Rectangle(Me.Width - 80, 5, 20, 20).Contains(e.Location): Me.ParentForm.WindowState = FormWindowState.Minimized
  45.                 'move title
  46.            Case e.Button = Windows.Forms.MouseButtons.Left And New Rectangle(0, 0, Width, MoveHeight).Contains(e.Location):Cap = True : MousePoint = e.Location
  47.         End Select
  48.     End Sub
  49.     Protected Overrides Sub OnMouseUp(e As MouseEventArgs)
  50.         MyBase.OnMouseUp(e) : Cap = False
  51.     End Sub
  52.     Protected Overrides Sub OnMouseMove(e As MouseEventArgs)
  53.         MyBase.OnMouseMove(e)
  54.         If Cap Then Parent.Location = MousePosition - MousePoint
  55.         Select Case True
  56.             Case New Rectangle(Me.Width - 30, 5, 20, 20).Contains(e.Location) : Cursor = Cursors.Hand : closebuttonhover = True : minibuttonhover = False : maxibuttonhover = False
  57.             Case New Rectangle(Me.Width - 55, 5, 20, 20).Contains(e.Location) : Cursor = Cursors.Hand : maxibuttonhover = True : closebuttonhover = False : minibuttonhover = False
  58.             Case New Rectangle(Me.Width - 80, 5, 20, 20).Contains(e.Location) : Cursor = Cursors.Hand : minibuttonhover = True : maxibuttonhover = False : closebuttonhover = False
  59.             Case Else : Cursor = Cursors.Arrow : closebuttonhover = False : minibuttonhover = False : maxibuttonhover = False
  60.         End Select
  61.         Me.Refresh()
  62.     End Sub
  63.     Protected Overrides Sub OnPaint(e As PaintEventArgs)
  64.         Dim gp As New GraphicsPath
  65.         Select Case ismemaxed
  66.             Case True : RoundCorners(gp, 0, 0, 0, 0, 30)
  67.             Case False : RoundCorners(gp, 20, 20, 0, 0, 30)
  68.         End Select
  69.  
  70.         Dim i As New Rectangle With {.Width = Me.Width, .Height = 30}
  71.         Dim TitleTopGradient As New LinearGradientBrush(i, Color.FromArgb(103, 115, 124), Color.FromArgb(35, 42, 61), LinearGradientMode.Vertical)
  72.         e.Graphics.SmoothingMode = SmoothingMode.AntiAlias
  73.         e.Graphics.DrawPath(Pens.Black, gp)
  74.         e.Graphics.FillPath(TitleTopGradient, gp)
  75.         e.Graphics.FillRectangle(New SolidBrush(Color.FromArgb(35, 42, 61)), New Rectangle(0, 30, Me.Width, Me.Height - 30))
  76.         e.Graphics.FillRectangle(New SolidBrush(Color.FromArgb(235, 233, 237)), New Rectangle(3, 30, Me.Width - 6, Me.Height - 33))
  77.         e.Graphics.DrawString(ParentForm.Text, DefaultFont, Brushes.White, New Point(40, 15 - DefaultFont.Height / 2))
  78.         e.Graphics.DrawIcon(ParentForm.Icon, New Rectangle(10, 5, 20, 20))
  79.         Dim p As New Pen(Brushes.White, 4)
  80.         Dim drawFont As New Font("Marlett", 10, FontStyle.Bold)
  81.  
  82.         e.Graphics.FillPath(New SolidBrush(Color.FromArgb(225, 72, 12)), RoundCorners2(10, 10, 10, 10, 20, 20, New Point(Me.Width - 30, 5))) 'X
  83.        e.Graphics.DrawString("r", drawFont, Brushes.White, New Rectangle(Me.Width - 29, 6, 20, 20), New StringFormat() With {.Alignment = StringAlignment.Near, .LineAlignment = StringAlignment.Center})
  84.  
  85.  
  86.  
  87.         e.Graphics.FillPath(New SolidBrush(Color.FromArgb(35, 42, 61)), RoundCorners2(10, 10, 10, 10, 20, 20, New Point(Me.Width - 55, 5))) '[]
  88.        e.Graphics.DrawString("1", drawFont, Brushes.White, New Rectangle(Me.Width - 54, 6, 20, 20), New StringFormat() With {.Alignment = StringAlignment.Near, .LineAlignment = StringAlignment.Center})
  89.  
  90.         '
  91.        e.Graphics.FillPath(New SolidBrush(Color.FromArgb(35, 42, 61)), RoundCorners2(10, 10, 10, 10, 20, 20, New Point(Me.Width - 80, 5))) '_
  92.        e.Graphics.DrawString("0", drawFont, Brushes.White, New Rectangle(Me.Width - 79, 6, 20, 20), New StringFormat() With {.Alignment = StringAlignment.Near, .LineAlignment = StringAlignment.Center})
  93.  
  94.  
  95.     End Sub
  96.  
  97.     Public Sub RoundCorners(ByRef p As GraphicsPath, ByVal leftTop As Int32, ByVal rightTop As Int32, ByVal rightBottom As Int32, ByVal leftBottom As Int32, ByVal mheight As Int32)
  98.         If leftTop <= 0 Then leftTop = 1
  99.         If rightTop <= 0 Then rightTop = 1
  100.         If rightBottom <= 0 Then rightBottom = 1
  101.         If leftBottom <= 0 Then leftBottom = 1
  102.         p.StartFigure()
  103.         p.AddArc(New Rectangle(0, 0, leftTop, leftTop), 180, 90)
  104.         p.AddArc(New Rectangle(Me.Width - rightTop, 0, rightTop, rightTop), -90, 90)
  105.         p.AddArc(New Rectangle(Me.Width - rightBottom, mheight - rightBottom, rightBottom, rightBottom), 0, 90)
  106.         p.AddArc(New Rectangle(0, mheight - leftBottom, leftBottom, leftBottom), 90, 90)
  107.         p.CloseFigure()
  108.     End Sub
  109.  
  110.     Public Function RoundCorners2(ByVal leftTop As Int32, ByVal rightTop As Int32, ByVal rightBottom As Int32, ByVal leftBottom As Int32, ByVal mheight As Int32, ByVal mwidth As Int32, ByVal d As Point)
  111.         Dim g As New GraphicsPath
  112.         If leftTop <= 0 Then leftTop = 1
  113.         If rightTop <= 0 Then rightTop = 1
  114.         If rightBottom <= 0 Then rightBottom = 1
  115.         If leftBottom <= 0 Then leftBottom = 1
  116.         g.StartFigure()
  117.         g.AddArc(New Rectangle(d.X + 0, d.Y + 0, leftTop, leftTop), 180, 90)
  118.         g.AddArc(New Rectangle(d.X + mwidth - rightTop, d.Y + 0, rightTop, rightTop), -90, 90)
  119.         g.AddArc(New Rectangle(d.X + mwidth - rightBottom, d.Y + mheight - rightBottom, rightBottom, rightBottom), 0, 90)
  120.         g.AddArc(New Rectangle(d.X + 0, d.Y + mheight - leftBottom, leftBottom, leftBottom), 90, 90)
  121.         g.CloseFigure()
  122.         Return g
  123.     End Function
  124.  
  125. End Class
Advertisement
Add Comment
Please, Sign In to add comment