Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Imports System.Drawing.Drawing2D
- Public Class Theme : Inherits ContainerControl
- 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
- Sub New()
- SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.UserPaint Or ControlStyles.ResizeRedraw Or ControlStyles.OptimizedDoubleBuffer, True)
- DoubleBuffered = True
- Me.Font = New Font("Segoe UI", 12)
- End Sub
- <DebuggerNonUserCode> _
- Protected Overrides Sub OnCreateControl()
- MyBase.OnCreateControl()
- ParentForm.FormBorderStyle = FormBorderStyle.None
- Select Case Debugger.IsAttached
- 'Blend in with Visual Studio background when you are debugging.
- Case True : ParentForm.TransparencyKey = Color.FromArgb(25, 25, 25) : ParentForm.BackColor = Color.FromArgb(25, 25, 25)
- Case False : ParentForm.TransparencyKey = Color.FromArgb(246, 246, 246) : ParentForm.BackColor = Color.FromArgb(246, 246, 246)
- End Select
- ParentForm.FindForm.StartPosition = FormStartPosition.CenterScreen
- Invalidate()
- End Sub
- <DebuggerStepThrough> _
- Private Sub Theme_Resize(sender As Object, e As EventArgs) Handles Me.Resize
- Try
- If ismemaxed = False Then
- Me.Location = New Point(0, 0)
- ParentForm.Size = Me.Size
- Else
- Me.Size = ParentForm.Size
- End If
- Catch ex As Exception
- End Try
- End Sub
- Protected Overrides Sub OnMouseDown(e As MouseEventArgs)
- MyBase.OnMouseDown(e)
- Select Case True
- 'The close button
- Case e.Button = Windows.Forms.MouseButtons.Left And New Rectangle(Me.Width - 30, 5, 20, 20).Contains(e.Location) : ParentForm.Close() : Application.Exit()
- 'maximize
- 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
- 'minimize
- Case e.Button = Windows.Forms.MouseButtons.Left And New Rectangle(Me.Width - 80, 5, 20, 20).Contains(e.Location): Me.ParentForm.WindowState = FormWindowState.Minimized
- 'move title
- Case e.Button = Windows.Forms.MouseButtons.Left And New Rectangle(0, 0, Width, MoveHeight).Contains(e.Location):Cap = True : MousePoint = e.Location
- End Select
- End Sub
- Protected Overrides Sub OnMouseUp(e As MouseEventArgs)
- MyBase.OnMouseUp(e) : Cap = False
- End Sub
- Protected Overrides Sub OnMouseMove(e As MouseEventArgs)
- MyBase.OnMouseMove(e)
- If Cap Then Parent.Location = MousePosition - MousePoint
- Select Case True
- Case New Rectangle(Me.Width - 30, 5, 20, 20).Contains(e.Location) : Cursor = Cursors.Hand : closebuttonhover = True : minibuttonhover = False : maxibuttonhover = False
- Case New Rectangle(Me.Width - 55, 5, 20, 20).Contains(e.Location) : Cursor = Cursors.Hand : maxibuttonhover = True : closebuttonhover = False : minibuttonhover = False
- Case New Rectangle(Me.Width - 80, 5, 20, 20).Contains(e.Location) : Cursor = Cursors.Hand : minibuttonhover = True : maxibuttonhover = False : closebuttonhover = False
- Case Else : Cursor = Cursors.Arrow : closebuttonhover = False : minibuttonhover = False : maxibuttonhover = False
- End Select
- Me.Refresh()
- End Sub
- Protected Overrides Sub OnPaint(e As PaintEventArgs)
- Dim gp As New GraphicsPath
- Select Case ismemaxed
- Case True : RoundCorners(gp, 0, 0, 0, 0, 30)
- Case False : RoundCorners(gp, 20, 20, 0, 0, 30)
- End Select
- Dim i As New Rectangle With {.Width = Me.Width, .Height = 30}
- Dim TitleTopGradient As New LinearGradientBrush(i, Color.FromArgb(103, 115, 124), Color.FromArgb(35, 42, 61), LinearGradientMode.Vertical)
- e.Graphics.SmoothingMode = SmoothingMode.AntiAlias
- e.Graphics.DrawPath(Pens.Black, gp)
- e.Graphics.FillPath(TitleTopGradient, gp)
- e.Graphics.FillRectangle(New SolidBrush(Color.FromArgb(35, 42, 61)), New Rectangle(0, 30, Me.Width, Me.Height - 30))
- e.Graphics.FillRectangle(New SolidBrush(Color.FromArgb(235, 233, 237)), New Rectangle(3, 30, Me.Width - 6, Me.Height - 33))
- e.Graphics.DrawString(ParentForm.Text, DefaultFont, Brushes.White, New Point(40, 15 - DefaultFont.Height / 2))
- e.Graphics.DrawIcon(ParentForm.Icon, New Rectangle(10, 5, 20, 20))
- Dim p As New Pen(Brushes.White, 4)
- Dim drawFont As New Font("Marlett", 10, FontStyle.Bold)
- ' e.Graphics.FillPath(New SolidBrush(Color.FromArgb(225, 72, 12)), RoundCorners2(10, 10, 10, 10, 20, 20, New Point(Me.Width - 30, 5))) 'X
- e.Graphics.DrawString("r", drawFont, Brushes.White, New Rectangle(Me.Width - 29, 6, 20, 20), New StringFormat() With {.Alignment = StringAlignment.Near, .LineAlignment = StringAlignment.Center})
- e.Graphics.DrawRectangle(Pens.Black, New Rectangle(Me.Width - 29, 5, 20, 20))
- ' e.Graphics.FillPath(New SolidBrush(Color.FromArgb(0, 35, 42, 61)), RoundCorners2(10, 10, 10, 10, 20, 20, New Point(Me.Width - 55, 5))) '[]
- e.Graphics.DrawString("1", drawFont, Brushes.White, New Rectangle(Me.Width - 54, 6, 20, 20), New StringFormat() With {.Alignment = StringAlignment.Near, .LineAlignment = StringAlignment.Center})
- e.Graphics.DrawRectangle(Pens.Black, New Rectangle(Me.Width - 55, 5, 20, 20))
- '
- ' e.Graphics.FillPath(New SolidBrush(Color.FromArgb(0, 35, 42, 61)), RoundCorners2(10, 10, 10, 10, 20, 20, New Point(Me.Width - 80, 5))) '_
- e.Graphics.DrawString("0", drawFont, Brushes.White, New Rectangle(Me.Width - 79, 6, 20, 20), New StringFormat() With {.Alignment = StringAlignment.Near, .LineAlignment = StringAlignment.Center})
- e.Graphics.DrawRectangle(Pens.Black, New Rectangle(Me.Width - 80, 5, 20, 20))
- End Sub
- 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)
- If leftTop <= 0 Then leftTop = 1
- If rightTop <= 0 Then rightTop = 1
- If rightBottom <= 0 Then rightBottom = 1
- If leftBottom <= 0 Then leftBottom = 1
- p.StartFigure()
- p.AddArc(New Rectangle(0, 0, leftTop, leftTop), 180, 90)
- p.AddArc(New Rectangle(Me.Width - rightTop, 0, rightTop, rightTop), -90, 90)
- p.AddArc(New Rectangle(Me.Width - rightBottom, mheight - rightBottom, rightBottom, rightBottom), 0, 90)
- p.AddArc(New Rectangle(0, mheight - leftBottom, leftBottom, leftBottom), 90, 90)
- p.CloseFigure()
- End Sub
- 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)
- Dim g As New GraphicsPath
- If leftTop <= 0 Then leftTop = 1
- If rightTop <= 0 Then rightTop = 1
- If rightBottom <= 0 Then rightBottom = 1
- If leftBottom <= 0 Then leftBottom = 1
- g.StartFigure()
- g.AddArc(New Rectangle(d.X + 0, d.Y + 0, leftTop, leftTop), 180, 90)
- g.AddArc(New Rectangle(d.X + mwidth - rightTop, d.Y + 0, rightTop, rightTop), -90, 90)
- g.AddArc(New Rectangle(d.X + mwidth - rightBottom, d.Y + mheight - rightBottom, rightBottom, rightBottom), 0, 90)
- g.AddArc(New Rectangle(d.X + 0, d.Y + mheight - leftBottom, leftBottom, leftBottom), 90, 90)
- g.CloseFigure()
- Return g
- End Function
- End Class
Advertisement
Add Comment
Please, Sign In to add comment