Guest User

ProperTheme [COMPLETE]

a guest
Dec 27th, 2014
273
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.87 KB | None | 0 0
  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.  
  22. <DebuggerStepThrough> _
  23. Private Sub Theme_Resize(sender As Object, e As EventArgs) Handles Me.Resize
  24. Try
  25. If ismemaxed = False Then
  26. Me.Location = New Point(0, 0)
  27. ParentForm.Size = Me.Size
  28. Else
  29. Me.Size = ParentForm.Size
  30. End If
  31. Catch
  32. End Try
  33. End Sub
  34. Protected Overrides Sub OnMouseDown(e As MouseEventArgs)
  35. MyBase.OnMouseDown(e)
  36. Select Case True
  37. 'The close button
  38. Case e.Button = Windows.Forms.MouseButtons.Left And New Rectangle(Me.Width - 30, 5, 20, 20).Contains(e.Location) : ParentForm.Close() : Application.Exit()
  39. 'maximize
  40. 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
  41. 'minimize
  42. Case e.Button = Windows.Forms.MouseButtons.Left And New Rectangle(Me.Width - 80, 5, 20, 20).Contains(e.Location): Me.ParentForm.WindowState = FormWindowState.Minimized
  43. 'move title
  44. Case (e.Button = Windows.Forms.MouseButtons.Left And New Rectangle(0, 0, Width, MoveHeight).Contains(e.Location) And ismemaxed = False) : Cap = True : Cursor = Cursors.SizeAll : MousePoint = e.Location
  45. End Select
  46. End Sub
  47. Protected Overrides Sub OnMouseUp(e As MouseEventArgs)
  48. MyBase.OnMouseUp(e) : Cap = False : Cursor = Cursors.Arrow
  49. End Sub
  50. Protected Overrides Sub OnMouseMove(e As MouseEventArgs)
  51. MyBase.OnMouseMove(e)
  52. If Cap And ismemaxed = False Then
  53. Parent.Location = MousePosition - MousePoint
  54. Else
  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. End If
  62. Me.Refresh()
  63. End Sub
  64. Protected Overrides Sub OnPaint(e As PaintEventArgs)
  65. Dim i As New Rectangle With {.Width = Me.Width, .Height = 30}
  66. Dim TitleTopGradient As New LinearGradientBrush(i, Color.FromArgb(103, 115, 124), Color.FromArgb(35, 42, 61), LinearGradientMode.Vertical)
  67. e.Graphics.SmoothingMode = SmoothingMode.AntiAlias
  68. Select Case ismemaxed
  69. Case True 'i fk'd up, this is false... dont notice me pweeze
  70. e.Graphics.DrawPath(Pens.Black, RoundCorners2(0, 0, 0, 0, 30, Me.Width, New Point(0, 0)))
  71. e.Graphics.FillPath(TitleTopGradient, RoundCorners2(0, 0, 0, 0, 30, Me.Width, New Point(0, 0)))
  72. Case False
  73. e.Graphics.DrawPath(Pens.Black, RoundCorners2(20, 20, 0, 0, 30, Me.Width, New Point(0, 0)))
  74. e.Graphics.FillPath(TitleTopGradient, RoundCorners2(20, 20, 0, 0, 30, Me.Width, New Point(0, 0)))
  75. End Select
  76. e.Graphics.FillRectangle(New SolidBrush(Color.FromArgb(35, 42, 61)), New Rectangle(0, 30, Me.Width, Me.Height - 30))
  77. e.Graphics.FillRectangle(New SolidBrush(Color.FromArgb(235, 233, 237)), New Rectangle(3, 30, Me.Width - 6, Me.Height - 33))
  78. e.Graphics.DrawString(ParentForm.Text, DefaultFont, Brushes.White, New Point(40, 15 - DefaultFont.Height / 2))
  79. e.Graphics.DrawIcon(ParentForm.Icon, New Rectangle(10, 5, 20, 20))
  80. Dim p As New Pen(Brushes.White, 4)
  81. Dim drawFont As New Font("Marlett", 10, FontStyle.Bold)
  82. Dim hpver As New LinearGradientBrush(i, Color.FromArgb(123, 135, 154), Color.FromArgb(45, 52, 71), LinearGradientMode.Vertical)
  83. Select Case True
  84. Case closebuttonhover
  85. e.Graphics.FillPath(hpver, RoundCorners2(10, 10, 10, 10, 20, 20, New Point(Me.Width - 30, 5)))
  86. Case minibuttonhover
  87. e.Graphics.FillPath(hpver, RoundCorners2(10, 10, 10, 10, 20, 20, New Point(Me.Width - 80, 5)))
  88. Case maxibuttonhover
  89. e.Graphics.FillPath(hpver, RoundCorners2(10, 10, 10, 10, 20, 20, New Point(Me.Width - 55, 5)))
  90.  
  91. End Select
  92.  
  93.  
  94.  
  95. e.Graphics.DrawString("r", drawFont, Brushes.White, New Rectangle(Me.Width - e.Graphics.MeasureString("r", drawFont).Width - 10, 6, 20, 20), New StringFormat() With {.Alignment = StringAlignment.Near, .LineAlignment = StringAlignment.Center})
  96. e.Graphics.DrawPath(Pens.Black, RoundCorners2(10, 10, 10, 10, 20, 20, New Point(Me.Width - 30, 5))) '54
  97. e.Graphics.DrawString("1", drawFont, Brushes.White, New Rectangle(Me.Width - e.Graphics.MeasureString("r", drawFont).Width - 35, 6, 20, 20), New StringFormat() With {.Alignment = StringAlignment.Near, .LineAlignment = StringAlignment.Center})
  98. e.Graphics.DrawPath(Pens.Black, RoundCorners2(10, 10, 10, 10, 20, 20, New Point(Me.Width - 55, 5)))
  99.  
  100.  
  101. e.Graphics.DrawString("0", drawFont, Brushes.White, New Rectangle(Me.Width - 79, 6, 20, 20), New StringFormat() With {.Alignment = StringAlignment.Near, .LineAlignment = StringAlignment.Center})
  102.  
  103. e.Graphics.DrawPath(Pens.Black, RoundCorners2(10, 10, 10, 10, 20, 20, New Point(Me.Width - 80, 5)))
  104.  
  105.  
  106.  
  107.  
  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