Advertisement
netrosly

PopCorn Container

Jul 6th, 2016
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 9.00 KB | None | 0 0
  1. Imports System.Drawing.Drawing2D
  2. Public Class MainContainer
  3.     Inherits ContainerControl
  4. #Region "Modules & Functions"
  5.     Public Property StyleType As Kind = Kind.Normal
  6.     Enum Kind
  7.         Normal
  8.         Windows
  9.         SmallView
  10.     End Enum
  11.     Public Sub FillRoundedRectangle(ByVal g As Drawing.Graphics, ByVal r As Rectangle, ByVal d As Integer, ByVal b As Brush)
  12.         Dim mode As Drawing2D.SmoothingMode = g.SmoothingMode
  13.         g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighSpeed
  14.         g.FillPie(b, r.X, r.Y, d, d, 180, 90)
  15.         g.FillPie(b, r.X + r.Width - d, r.Y, d, d, 270, 90)
  16.         g.FillPie(b, r.X, r.Y + r.Height - d, d, d, 90, 90)
  17.         g.FillPie(b, r.X + r.Width - d, r.Y + r.Height - d, d, d, 0, 90)
  18.         g.FillRectangle(b, CInt(r.X + d / 2), r.Y, r.Width - d, CInt(d / 2))
  19.         g.FillRectangle(b, r.X, CInt(r.Y + d / 2), r.Width, CInt(r.Height - d))
  20.         g.FillRectangle(b, CInt(r.X + d / 2), CInt(r.Y + r.Height - d / 2), CInt(r.Width - d), CInt(d / 2))
  21.         g.SmoothingMode = mode
  22.     End Sub
  23. #End Region
  24.     Enum TypeIcon
  25.         UseFormIcon
  26.         CustomImage
  27.         NoIcon
  28.     End Enum
  29.     Property ShowNotes As Boolean = False
  30.     Property NoteNum As String = "0"
  31.     Property IconDisplayType As TypeIcon
  32.     Property Image As Image
  33.  
  34.     Sub New()
  35.  
  36.         Me.DoubleBuffered = True
  37.         Me.Dock = DockStyle.Fill
  38.         Me.Padding = New Padding(1, 66, 1, 1)
  39.     End Sub
  40.     Private Sub MainContainer_Paint(sender As Object, e As PaintEventArgs) Handles Me.Paint
  41.  
  42.         'Background
  43.     e.Graphics.Clear(Color.FromArgb(18, 18, 18))
  44.         e.Graphics.SmoothingMode = SmoothingMode.AntiAlias
  45.         If StyleType = Kind.Normal Then
  46.             'Header
  47.       e.Graphics.FillRectangle(New SolidBrush(Color.FromArgb(18, 18, 18)), New Rectangle(0, 0, Me.Width - 1, 60))
  48.             Dim nrect = New Rectangle(0, 61, Me.Width - 1, 5)
  49.       Dim brushs = New LinearGradientBrush(nrect, Color.FromArgb(50, Color.Black), Color.FromArgb(18, 18, 18), LinearGradientMode.Vertical)
  50.             e.Graphics.FillRectangle(brushs, nrect)
  51.             '//////////////
  52.             'Buttons//////
  53.  
  54.             'Minimize
  55.             If Minihover = True Then
  56.         e.Graphics.FillEllipse(New SolidBrush(Color.FromArgb(74, 75, 78)), New Rectangle(Me.Width - 38, 8, 12, 12))
  57.         e.Graphics.DrawString("0", New Font("Webdings", 7.1, FontStyle.Regular), New SolidBrush(Color.FromArgb(44, 45, 49)), New Rectangle(Me.Width - 38, 5, 12, 12))
  58.             Else
  59.         e.Graphics.FillEllipse(New SolidBrush(Color.FromArgb(64, 65, 68)), New Rectangle(Me.Width - 38, 8, 12, 12))
  60.         e.Graphics.DrawString("0", New Font("Webdings", 7.1, FontStyle.Regular), New SolidBrush(Color.FromArgb(44, 45, 49)), New Rectangle(Me.Width - 38, 5, 12, 12))
  61.             End If
  62.             'Maxmize
  63.       'If Maxhover = True Then
  64.       '    e.Graphics.FillEllipse(New SolidBrush(Color.FromArgb(74, 75, 78)), New Rectangle(Me.Width - 40, 8, 12, 12)) '47, 48, 52
  65.       '    e.Graphics.DrawString("+", New Font("Arial", 9.5, FontStyle.Regular), New SolidBrush(Color.FromArgb(44, 45, 49)), New Rectangle(Me.Width - 39.5, 6, 12, 12))
  66.       'Else
  67.       '    e.Graphics.FillEllipse(New SolidBrush(Color.FromArgb(64, 65, 68)), New Rectangle(Me.Width - 40, 8, 12, 12)) '47, 48, 52
  68.       '    e.Graphics.DrawString("+", New Font("Arial", 9.5, FontStyle.Regular), New SolidBrush(Color.FromArgb(44, 45, 49)), New Rectangle(Me.Width - 39.5, 6, 12, 12))
  69.       'End If
  70.             If Exithover = True Then
  71.                 'Close
  72.         e.Graphics.FillEllipse(New SolidBrush(Color.FromArgb(74, 75, 78)), New Rectangle(Me.Width - 22, 8, 12, 12))
  73.                 e.Graphics.DrawString("r", New Font("Webdings", 7.1, FontStyle.Regular), New SolidBrush(Color.FromArgb(44, 45, 49)), New Rectangle(Me.Width - 22, 9, 12, 12))
  74.             Else
  75.                 'Close
  76.                 e.Graphics.FillEllipse(New SolidBrush(Color.FromArgb(64, 65, 68)), New Rectangle(Me.Width - 22, 8, 12, 12))
  77.                 e.Graphics.DrawString("r", New Font("Webdings", 7.1, FontStyle.Regular), New SolidBrush(Color.FromArgb(44, 45, 49)), New Rectangle(Me.Width - 22, 9, 12, 12))
  78.             End If
  79.  
  80.             '/////////////
  81.             'ShadowText
  82.             e.Graphics.DrawString(ParentForm.Text, New Font("Arial", 11.5, FontStyle.Regular), New SolidBrush(Color.FromArgb(22, 24, 28)), New Rectangle(0, 5, Me.Width - 1, 20), New StringFormat() With {.Alignment = StringAlignment.Center, .LineAlignment = StringAlignment.Center})
  83.             'Text
  84.             e.Graphics.DrawString(ParentForm.Text, New Font("Arial", 11.5, FontStyle.Regular), Brushes.White, New Rectangle(0, 6, Me.Width - 1, 20), New StringFormat() With {.Alignment = StringAlignment.Center, .LineAlignment = StringAlignment.Center})
  85.             'icon
  86.             Select Case IconDisplayType
  87.                 Case TypeIcon.CustomImage
  88.                     e.Graphics.DrawImage(Image, New Rectangle(5, 4, 24, 24))
  89.                 Case TypeIcon.UseFormIcon
  90.                     e.Graphics.DrawImage(ParentForm.Icon.ToBitmap, New Rectangle(2, -5, 28, 28))
  91.                 Case TypeIcon.NoIcon
  92.                     If Not NoteNum = "0" Then
  93.                         e.Graphics.FillRectangle(New SolidBrush(Color.FromArgb(251, 83, 150)), New Rectangle(2, 4, 20, 6))
  94.                         e.Graphics.FillRectangle(New SolidBrush(Color.FromArgb(231, 63, 130)), New Rectangle(2, 8, 20, 2))
  95.                         e.Graphics.FillRectangle(New SolidBrush(Color.FromArgb(251, 83, 150)), New Rectangle(2, 14, 20, 6))
  96.                         e.Graphics.FillRectangle(New SolidBrush(Color.FromArgb(231, 63, 130)), New Rectangle(2, 18, 20, 2))
  97.                     Else
  98.                         e.Graphics.FillRectangle(New SolidBrush(Color.FromArgb(163, 163, 163)), New Rectangle(2, 4, 20, 6))
  99.                         e.Graphics.FillRectangle(New SolidBrush(Color.FromArgb(183, 183, 183)), New Rectangle(2, 8, 20, 2))
  100.                         e.Graphics.FillRectangle(New SolidBrush(Color.FromArgb(163, 163, 163)), New Rectangle(2, 14, 20, 6))
  101.                         e.Graphics.FillRectangle(New SolidBrush(Color.FromArgb(183, 183, 183)), New Rectangle(2, 18, 20, 2))
  102.                     End If
  103.  
  104.             End Select
  105.             Me.Padding = New Padding(1, 66, 1, 1)
  106.         ElseIf StyleType = Kind.Windows Then
  107.             e.Graphics.FillRectangle(New SolidBrush(Color.FromArgb(22, 23, 27)), New Rectangle(0, 0, Me.Width - 1, 33))
  108.             Dim nrect = New Rectangle(0, 28, Me.Width - 1, 5)
  109.             Dim brushs = New LinearGradientBrush(nrect, Color.FromArgb(50, Color.Black), Color.FromArgb(22, 24, 28), LinearGradientMode.Vertical)
  110.             e.Graphics.FillRectangle(brushs, nrect)
  111.             Me.Padding = New Padding(1, 33, 1, 1)
  112.         ElseIf StyleType = Kind.SmallView Then
  113.             Me.Padding = New Padding(1, 1, 1, 1)
  114.         End If
  115.     End Sub
  116. #Region "ThemeDraggable"
  117.  
  118.     Private savePoint As New Point(0, 0)
  119.     Private isDragging As Boolean = False
  120.     Private Minihover As Boolean = False
  121.     Private Maxhover As Boolean = False
  122.     Private Exithover As Boolean = False
  123.     Public Event Clickedd()
  124.     Protected Overrides Sub OnMouseDown(e As MouseEventArgs)
  125.         Dim dragRect As New Rectangle(0, 0, Me.Width - 58, 61)
  126.         If dragRect.Contains(New Point(e.X, e.Y)) Then
  127.             isDragging = True
  128.             savePoint = New Point(e.X, e.Y)
  129.         End If
  130.         If New Rectangle(5, 4, 36, 24).Contains(e.X, e.Y) Then
  131.             RaiseEvent Clickedd()
  132.         End If
  133.         Dim clickRect As New Rectangle(Me.Width - 22, 8, 12, 12)
  134.         If clickRect.Contains(New Point(e.X, e.Y)) Then
  135.             Environment.[Exit](0)
  136.         End If
  137.     If New Rectangle(Me.Width - 38, 8, 12, 12).Contains(New Point(mouseX, mouseY)) Then
  138.       FindForm.WindowState = FormWindowState.Minimized
  139.     End If
  140.         '
  141.         MyBase.OnMouseDown(e)
  142.     End Sub
  143.  
  144.     Protected Overrides Sub OnMouseUp(e As MouseEventArgs)
  145.         isDragging = False
  146.         MyBase.OnMouseUp(e)
  147.     End Sub
  148.  
  149.     Private mouseX As Integer
  150.     Private mouseY As Integer
  151.     Protected Overrides Sub OnMouseMove(e As MouseEventArgs)
  152.  
  153.         mouseX = e.X
  154.         mouseY = e.Y
  155.         If isDragging Then
  156.             Dim screenPoint As Point = PointToScreen(e.Location)
  157.  
  158.             FindForm().Location = New Point(screenPoint.X - Me.savePoint.X, screenPoint.Y - Me.savePoint.Y)
  159.         End If
  160.         If New Rectangle(Me.Width - 40, 8, 12, 12).Contains(New Point(mouseX, mouseY)) Then
  161.             Maxhover = True
  162.         Else
  163.             Maxhover = False
  164.         End If
  165.         If New Rectangle(Me.Width - 58, 8, 12, 12).Contains(New Point(mouseX, mouseY)) Then
  166.             Minihover = True
  167.         Else
  168.             Minihover = False
  169.         End If
  170.         If New Rectangle(Me.Width - 22, 8, 12, 12).Contains(e.X, e.Y) Then
  171.             Exithover = True
  172.         Else
  173.             Exithover = False
  174.         End If
  175.         MyBase.OnMouseMove(e)
  176.         Invalidate()
  177.     End Sub
  178.  
  179. #End Region
  180. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement