Advertisement
netrosly

LoginBox - GDI

Feb 1st, 2015
473
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 17.96 KB | None | 0 0
  1. 'Random Controls: LoginBox
  2. 'By Nettro ;P
  3. Imports System.Drawing.Drawing2D
  4. Imports System.ComponentModel
  5.  
  6. Public Class LoginBox
  7.     Inherits Panel
  8.     Event Clicked()
  9.     Protected Overrides Sub OnCreateControl()
  10.         MyBase.OnCreateControl()
  11.         If Not Controls.Contains(TB) Then
  12.             Controls.Add(TB)
  13.             Controls.Add(TB2)
  14.         End If
  15.     End Sub
  16. #Region "Modules & Functions"
  17.     Public Sub DrawRoundRect(g As Graphics, p As Pen, x As Single, y As Single, width As Single, height As Single, _
  18.        radius As Single)
  19.         Dim gp As New GraphicsPath()
  20.  
  21.         gp.AddLine(x + radius, y, x + width - (radius * 2), y)
  22.         ' Line
  23.         gp.AddArc(x + width - (radius * 2), y, radius * 2, radius * 2, 270, 90)
  24.         ' Corner
  25.         gp.AddLine(x + width, y + radius, x + width, y + height - (radius * 2))
  26.         ' Line
  27.         gp.AddArc(x + width - (radius * 2), y + height - (radius * 2), radius * 2, radius * 2, 0, 90)
  28.         ' Corner
  29.         gp.AddLine(x + width - (radius * 2), y + height, x + radius, y + height)
  30.         ' Line
  31.         gp.AddArc(x, y + height - (radius * 2), radius * 2, radius * 2, 90, 90)
  32.         ' Corner
  33.         gp.AddLine(x, y + height - (radius * 2), x, y + radius)
  34.         ' Line
  35.         gp.AddArc(x, y, radius * 2, radius * 2, 180, 90)
  36.         ' Corner
  37.         gp.CloseFigure()
  38.  
  39.         g.DrawPath(p, gp)
  40.         gp.Dispose()
  41.     End Sub
  42.     Public Sub FillRoundedRectangle(ByVal g As Drawing.Graphics, ByVal r As Rectangle, ByVal d As Integer, ByVal b As Brush)
  43.         Dim mode As Drawing2D.SmoothingMode = g.SmoothingMode
  44.         g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality
  45.         g.FillPie(b, r.X, r.Y, d, d, 180, 90)
  46.         g.FillPie(b, r.X + r.Width - d, r.Y, d, d, 270, 90)
  47.         g.FillPie(b, r.X, r.Y + r.Height - d, d, d, 90, 90)
  48.         g.FillPie(b, r.X + r.Width - d, r.Y + r.Height - d, d, d, 0, 90)
  49.         g.FillRectangle(b, CInt(r.X + d / 2), r.Y, r.Width - d, CInt(d / 2))
  50.         g.FillRectangle(b, r.X, CInt(r.Y + d / 2), r.Width, CInt(r.Height - d))
  51.         g.FillRectangle(b, CInt(r.X + d / 2), CInt(r.Y + r.Height - d / 2), CInt(r.Width - d), CInt(d / 2))
  52.         g.SmoothingMode = mode
  53.     End Sub
  54.     Public Sub FillNotTopRoundedRectangle(ByVal g As Drawing.Graphics, ByVal r As Rectangle, ByVal d As Integer, ByVal b As Brush)
  55.         Dim mode As Drawing2D.SmoothingMode = g.SmoothingMode
  56.         g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality
  57.         g.FillPie(b, r.X, r.Y, 1, 1, 180, 90)
  58.         g.FillPie(b, r.X + r.Width - d, r.Y, 1, 1, 270, 90)
  59.         g.FillPie(b, r.X, r.Y + r.Height - d, d, d, 90, 90)
  60.         g.FillPie(b, r.X + r.Width - d, r.Y + r.Height - d, d, d, 0, 90)
  61.         ' g.FillRectangle(b, CInt(r.X + d / 2), r.Y, r.Width - d, CInt(d / 2))
  62.         g.FillRectangle(b, r.X, CInt(r.Y + d / 2), r.Width, CInt(r.Height - d))
  63.         g.FillRectangle(b, CInt(r.X + d / 2), CInt(r.Y + r.Height - d / 2), CInt(r.Width - d), CInt(d / 2))
  64.         g.SmoothingMode = mode
  65.     End Sub
  66.  
  67. #End Region
  68.     Sub New()
  69.         Me.Size = New Size(234, 178)
  70.         SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.UserPaint Or _
  71.            ControlStyles.ResizeRedraw Or ControlStyles.OptimizedDoubleBuffer Or _
  72.            ControlStyles.SupportsTransparentBackColor, True)
  73.         DoubleBuffered = True
  74.         BackColor = Color.Transparent
  75.         Parent = FindForm()
  76.         'Textbox 1
  77.         MyBase.Font = New Font("Arial", 12, FontStyle.Regular)
  78.         TB = New Windows.Forms.TextBox
  79.         TB.BackColor = _BaseColour
  80.         TB.Font = New Font("Segoe UI", 9)
  81.         TB.Text = Text
  82.         TB.BackColor = _BaseColour
  83.         TB.ForeColor = _TextColour
  84.         TB.MaxLength = _MaxLength
  85.         TB.Multiline = False
  86.         TB.ReadOnly = _ReadOnly
  87.         TB.UseSystemPasswordChar = _UseSystemPasswordChar
  88.         TB.BorderStyle = BorderStyle.None
  89.         TB.Location = New Point(20, 20)
  90.         TB.Width = Width - 10
  91.         TB.Font = MyBase.Font
  92.         'Textbox2
  93.         TB2 = New Windows.Forms.TextBox
  94.         TB2.BackColor = _BaseColour
  95.         TB2.Font = New Font("Segoe UI", 9)
  96.         TB2.Text = Text
  97.         TB2.BackColor = _BaseColour
  98.         TB2.ForeColor = _TextColour
  99.         TB2.MaxLength = _MaxLength
  100.         TB2.Multiline = False
  101.         TB2.ReadOnly = _ReadOnly
  102.         TB2.UseSystemPasswordChar = _UseSystemPasswordChar
  103.         TB2.BorderStyle = BorderStyle.None
  104.         TB2.Location = New Point(20, 85)
  105.         TB2.Width = Width - 10
  106.         TB2.Font = MyBase.Font
  107.     End Sub
  108. #Region "paint"
  109.     Private Sub LoginBox_Paint(sender As Object, e As PaintEventArgs) Handles Me.Paint
  110.         e.Graphics.SmoothingMode = SmoothingMode.AntiAlias
  111.  
  112.         Dim Rect = New Rectangle(0, 0, Me.Width, Me.Height - 10)
  113.         Dim GradBrush = New LinearGradientBrush(New Rectangle(0, 0, Me.Width, Me.Height - 64), Color.FromArgb(243, 240, 243), Color.FromArgb(212, 207, 203), 90.0!)
  114.         FillRoundedRectangle(e.Graphics, Rect, 18, GradBrush)
  115.         '  DrawRoundRect(e.Graphics, New Pen(Color.FromArgb(240, 240, 240)), 0, 0, Me.Width, Me.Height, 18)
  116.         If clickedd = False Then
  117.             Rect = New Rectangle(0, Me.Height - 70, Me.Width, 70)
  118.             GradBrush = New LinearGradientBrush(Rect, Color.FromArgb(147, 179, 201), Color.FromArgb(68, 93, 113), 90.0!)
  119.             FillNotTopRoundedRectangle(e.Graphics, Rect, 18, GradBrush)
  120.         Else
  121.             Rect = New Rectangle(0, Me.Height - 70, Me.Width, 70)
  122.             GradBrush = New LinearGradientBrush(Rect, Color.FromArgb(68, 93, 113), Color.FromArgb(48, 73, 93), 90.0!)
  123.             FillNotTopRoundedRectangle(e.Graphics, Rect, 18, GradBrush)
  124.         End If
  125.         GradBrush = New LinearGradientBrush(Rect, Color.FromArgb(50, Color.Black), Color.FromArgb(147, 179, 201), 90.0!)
  126.         Rect = New Rectangle(0, Me.Height - 64, Me.Width, 4)
  127.         e.Graphics.FillRectangle(GradBrush, Rect)
  128.         e.Graphics.DrawLine(New Pen(Color.FromArgb(191, 191, 191)), New Point(0, 60), New Point(Me.Width, 60))
  129.         e.Graphics.FillRectangle(New SolidBrush(Color.FromArgb(240, 240, 240)), New Rectangle(6, 0, 5, 10))
  130.         e.Graphics.FillRectangle(New SolidBrush(Color.FromArgb(240, 240, 240)), New Rectangle(Me.Width - 10, 0, 5, 5))
  131.         e.Graphics.FillRectangle(New SolidBrush(Color.FromArgb(240, 240, 240)), New Rectangle(0, 5, Me.Width, 10))
  132.         'Fix Bottom
  133.         If clickedd = False Then
  134.             e.Graphics.FillRectangle(New SolidBrush(Color.FromArgb(77, 103, 123)), New Rectangle(8, Me.Height - 8, 2, 7))
  135.             e.Graphics.FillRectangle(New SolidBrush(Color.FromArgb(77, 103, 123)), New Rectangle(Me.Width - 10, Me.Height - 8, 2, 7))
  136.             e.Graphics.FillRectangle(New SolidBrush(Color.FromArgb(77, 103, 123)), New Rectangle(0, Me.Height - 10, Me.Width, 2))
  137.         Else
  138.             e.Graphics.FillRectangle(New SolidBrush(Color.FromArgb(48, 73, 93)), New Rectangle(8, Me.Height - 8, 2, 7))
  139.             e.Graphics.FillRectangle(New SolidBrush(Color.FromArgb(48, 73, 93)), New Rectangle(Me.Width - 10, Me.Height - 8, 2, 7))
  140.             e.Graphics.FillRectangle(New SolidBrush(Color.FromArgb(48, 73, 93)), New Rectangle(0, Me.Height - 10, Me.Width, 2))
  141.         End If
  142.  
  143.         If clickedd = False Then
  144.             If New Rectangle(10, Me.Height - 60, Me.Width - 20, 70).Contains(mouseX, mouseY) Then
  145.                 'e.Graphics.FillEllipse(New SolidBrush(Color.FromArgb(50, Color.White)), New Rectangle(mouseX - 7, mouseY - 7, 14, 14))
  146.                 'e.Graphics.FillEllipse(New SolidBrush(Color.FromArgb(60, Color.White)), New Rectangle(mouseX - 8, mouseY - 8, 16, 16))
  147.                 'e.Graphics.FillEllipse(New SolidBrush(Color.FromArgb(70, Color.White)), New Rectangle(mouseX - 10, mouseY - 10, 20, 20))
  148.                 'e.Graphics.FillEllipse(New SolidBrush(Color.FromArgb(100, Color.White)), New Rectangle(mouseX - 3, mouseY - 3, 5, 5))
  149.                 e.Graphics.DrawString("Sign In", New Font("Arial", 18, FontStyle.Regular), New SolidBrush(Color.FromArgb(50, Color.White)), New Rectangle(0, Me.Height - 65, Me.Width, 70), New StringFormat With {.Alignment = StringAlignment.Center, .LineAlignment = StringAlignment.Center})
  150.                 e.Graphics.DrawString("Sign In", New Font("Arial", 17, FontStyle.Regular), New SolidBrush(Color.FromArgb(50, Color.White)), New Rectangle(0, Me.Height - 65, Me.Width, 70), New StringFormat With {.Alignment = StringAlignment.Center, .LineAlignment = StringAlignment.Center})
  151.             End If
  152.         End If
  153.         DrawRoundRect(e.Graphics, New Pen(Color.FromArgb(44, 44, 44)), 1, 1, Me.Width - 3, Me.Height - 3, 4)
  154.         'Textboxs
  155.         TB.Text = TB.Text
  156.         TB.BackColor = _BaseColour
  157.         TB.ForeColor = _TextColour
  158.         TB.Location = New Point(20, 20)
  159.         TB.Width = Width - 40
  160.         TB2.Text = TB2.Text
  161.         TB2.BackColor = _BaseColour2
  162.         TB2.ForeColor = _TextColour2
  163.         TB2.Location = New Point(20, 85)
  164.         TB2.Width = Width - 40
  165.         'Sign In
  166.         e.Graphics.DrawString("Sign In", New Font("Arial", 16, FontStyle.Regular), Brushes.White, New Rectangle(0, Me.Height - 65, Me.Width, 70), New StringFormat With {.Alignment = StringAlignment.Center, .LineAlignment = StringAlignment.Center})
  167.         clickedd = False
  168.     End Sub
  169. #End Region
  170. #Region "Properties & Events"
  171.     Public WithEvents TB2 As TextBox
  172.     Public WithEvents TB As New TextBox
  173.     Private _BaseColour As Color = Color.FromArgb(236, 233, 234)
  174.     Private _BorderColour As Color = Color.FromArgb(163, 190, 146)
  175.     Private _LineColour As Color = Color.FromArgb(221, 221, 221)
  176.     Private _TextColour As Color = Color.FromArgb(149, 147, 148)
  177.     Private _TextAlign As HorizontalAlignment = HorizontalAlignment.Left
  178.     Private _MaxLength As Integer = 32767
  179.     Private _ReadOnly As Boolean
  180.     Private _UseSystemPasswordChar As Boolean
  181.     Private _Text As String = "Username"
  182.     Private _Text2 As String = "Password"
  183.     Private _BaseColour2 As Color = Color.FromArgb(218, 213, 211)
  184.     Private _BorderColour2 As Color = Color.FromArgb(163, 190, 146)
  185.     Private _LineColour2 As Color = Color.FromArgb(221, 221, 221)
  186.     Private _TextColour2 As Color = Color.FromArgb(149, 147, 148)
  187.     Private _TextAlign2 As HorizontalAlignment = HorizontalAlignment.Left
  188.     Private _MaxLength2 As Integer = 32767
  189.     Private _ReadOnly2 As Boolean
  190.     Private _UseSystemPasswordChar2 As Boolean
  191.     Private _Multiline As Boolean
  192.     Public Sub SelectAll()
  193.         TB.Focus()
  194.         TB.SelectAll()
  195.         Invalidate()
  196.     End Sub
  197.  
  198.     <Category("Username")>
  199.     Public Property BaseColour As Color
  200.         Get
  201.             Return _BaseColour
  202.         End Get
  203.         Set(value As Color)
  204.             _BaseColour = value
  205.         End Set
  206.     End Property
  207.  
  208.     <Category("Username")>
  209.     Public Property BorderColour As Color
  210.         Get
  211.             Return _BorderColour
  212.         End Get
  213.         Set(value As Color)
  214.             _BorderColour = value
  215.         End Set
  216.     End Property
  217.  
  218.     <Category("Username")>
  219.     Public Property LineColour As Color
  220.         Get
  221.             Return _LineColour
  222.         End Get
  223.         Set(value As Color)
  224.             _LineColour = value
  225.         End Set
  226.     End Property
  227.  
  228.     <Category("Username")>
  229.     Public Property TextColour As Color
  230.         Get
  231.             Return _TextColour
  232.         End Get
  233.         Set(value As Color)
  234.             _TextColour = value
  235.         End Set
  236.     End Property
  237.  
  238.  
  239.  
  240.     <Category("Username")>
  241.     Property TextAlign() As HorizontalAlignment
  242.         Get
  243.             Return _TextAlign
  244.         End Get
  245.         Set(ByVal value As HorizontalAlignment)
  246.             _TextAlign = value
  247.             If TB IsNot Nothing Then
  248.                 TB.TextAlign = value
  249.             End If
  250.         End Set
  251.     End Property
  252.  
  253.     <Category("Username")>
  254.     Property MaxLength() As Integer
  255.         Get
  256.             Return _MaxLength
  257.         End Get
  258.         Set(ByVal value As Integer)
  259.             _MaxLength = value
  260.             If TB IsNot Nothing Then
  261.                 TB.MaxLength = value
  262.             End If
  263.         End Set
  264.     End Property
  265.  
  266.     <Category("Username")>
  267.     Property [ReadOnly]() As Boolean
  268.         Get
  269.             Return _ReadOnly
  270.         End Get
  271.         Set(ByVal value As Boolean)
  272.             _ReadOnly = value
  273.             If TB IsNot Nothing Then
  274.                 TB.ReadOnly = value
  275.             End If
  276.         End Set
  277.     End Property
  278.  
  279.     <Category("Username")>
  280.     Property UseSystemPasswordChar() As Boolean
  281.         Get
  282.             Return _UseSystemPasswordChar
  283.         End Get
  284.         Set(ByVal value As Boolean)
  285.             _UseSystemPasswordChar = value
  286.             If TB IsNot Nothing Then
  287.                 TB.UseSystemPasswordChar = value
  288.             End If
  289.         End Set
  290.     End Property
  291.     <Category("Username")>
  292.     Property Textt As String
  293.         Get
  294.             Return _Text
  295.         End Get
  296.         Set(ByVal value As String)
  297.             _Text = value
  298.             If TB IsNot Nothing Then
  299.                 TB.Text = value
  300.             End If
  301.         End Set
  302.     End Property
  303.  
  304.  
  305.     'Password
  306.     <Category("Password")>
  307.     Property Text2 As String
  308.         Get
  309.             Return _Text2
  310.         End Get
  311.         Set(ByVal value As String)
  312.             _Text = value
  313.             If TB2 IsNot Nothing Then
  314.                 TB2.Text = value
  315.             End If
  316.         End Set
  317.     End Property
  318.     <Category("Password")>
  319.     Public Property BaseColour2 As Color
  320.         Get
  321.             Return _BaseColour2
  322.         End Get
  323.         Set(value As Color)
  324.             _BaseColour2 = value
  325.         End Set
  326.     End Property
  327.  
  328.     <Category("Password")>
  329.     Public Property BorderColour2 As Color
  330.         Get
  331.             Return _BorderColour2
  332.         End Get
  333.         Set(value As Color)
  334.             _BorderColour2 = value
  335.         End Set
  336.     End Property
  337.  
  338.     <Category("Password")>
  339.     Public Property LineColour2 As Color
  340.         Get
  341.             Return _LineColour2
  342.         End Get
  343.         Set(value As Color)
  344.             _LineColour2 = value
  345.         End Set
  346.     End Property
  347.  
  348.     <Category("Password")>
  349.     Public Property TextColour2 As Color
  350.         Get
  351.             Return _TextColour2
  352.         End Get
  353.         Set(value As Color)
  354.             _TextColour2 = value
  355.         End Set
  356.     End Property
  357.  
  358.  
  359.  
  360.     <Category("Password")>
  361.     Property TextAlign2() As HorizontalAlignment
  362.         Get
  363.             Return _TextAlign2
  364.         End Get
  365.         Set(ByVal value As HorizontalAlignment)
  366.             _TextAlign = value
  367.             If TB2 IsNot Nothing Then
  368.                 TB2.TextAlign = value
  369.             End If
  370.         End Set
  371.     End Property
  372.  
  373.     <Category("Password")>
  374.     Property MaxLength2() As Integer
  375.         Get
  376.             Return _MaxLength2
  377.         End Get
  378.         Set(ByVal value As Integer)
  379.             _MaxLength2 = value
  380.             If TB2 IsNot Nothing Then
  381.                 TB2.MaxLength = value
  382.             End If
  383.         End Set
  384.     End Property
  385.  
  386.     <Category("Password")>
  387.     Property [ReadOnly2]() As Boolean
  388.         Get
  389.             Return _ReadOnly2
  390.         End Get
  391.         Set(ByVal value As Boolean)
  392.             _ReadOnly2 = value
  393.             If TB2 IsNot Nothing Then
  394.                 TB2.ReadOnly = value
  395.             End If
  396.         End Set
  397.     End Property
  398.  
  399.     <Category("Password")>
  400.     Property UseSystemPasswordChar2() As Boolean
  401.         Get
  402.             Return _UseSystemPasswordChar2
  403.         End Get
  404.         Set(ByVal value As Boolean)
  405.             _UseSystemPasswordChar2 = value
  406.             If TB2 IsNot Nothing Then
  407.                 TB2.UseSystemPasswordChar = value
  408.             End If
  409.         End Set
  410.     End Property
  411.     <Category("Password")>
  412.     Overrides Property Text As String
  413.         Get
  414.             Return _Text2
  415.         End Get
  416.         Set(ByVal value As String)
  417.             _Text2 = value
  418.             If TB2 IsNot Nothing Then
  419.                 TB2.Text = value
  420.             End If
  421.         End Set
  422.     End Property
  423.  
  424.     <Category("Control")>
  425.     Overrides Property Font As Font
  426.         Get
  427.             Return MyBase.Font
  428.         End Get
  429.         Set(ByVal value As Font)
  430.             MyBase.Font = value
  431.             If TB2 IsNot Nothing Then
  432.                 TB2.Font = value
  433.                 TB2.Location = New Point(3, 5)
  434.                 TB2.Width = Width - 6
  435.                 TB.Font = value
  436.                 TB.Location = New Point(3, 5)
  437.                 TB.Width = Width - 6
  438.                 If Not _Multiline Then
  439.                     Height = TB.Height + 11
  440.                 End If
  441.             End If
  442.         End Set
  443.     End Property
  444.  
  445.  
  446.     Private Sub OnBaseTextChanged(ByVal s As Object, ByVal e As EventArgs)
  447.         _Text = TB.Text
  448.         _Text2 = TB2.Text
  449.     End Sub
  450.  
  451.     Protected Overrides Sub OnResize(ByVal e As EventArgs)
  452.  
  453.         TB.Location = New Point(20, 20)
  454.         TB.Width = Width - 10
  455.         'TB2.Location = New Point(85, 85)
  456.         'TB2.Width = Width - 10
  457.  
  458.         MyBase.OnResize(e)
  459.     End Sub
  460.  
  461. #End Region
  462. #Region "ThemeDraggable"
  463.     Dim clickedd As Boolean = False
  464.     Protected Overrides Sub OnMouseDown(e As MouseEventArgs)
  465.         If New Rectangle(0, Me.Height - 60, Me.Width, 60).Contains(mouseX, mouseY) Then
  466.             If e.Button = Windows.Forms.MouseButtons.Left Then
  467.                 RaiseEvent Clicked()
  468.                 clickedd = True
  469.             End If
  470.         End If
  471.         '
  472.         MyBase.OnMouseDown(e)
  473.     End Sub
  474.  
  475.     Protected Overrides Sub OnMouseUp(e As MouseEventArgs)
  476.  
  477.         MyBase.OnMouseUp(e)
  478.     End Sub
  479.  
  480.     Private mouseX As Integer
  481.     Private mouseY As Integer
  482.     Protected Overrides Sub OnMouseMove(e As MouseEventArgs)
  483.  
  484.         mouseX = e.X
  485.         mouseY = e.Y
  486.         If New Rectangle(0, Me.Height - 70, Me.Width, 70).Contains(mouseX, mouseY) Then
  487.             Cursor = Cursors.Hand
  488.         Else
  489.             Cursor = Cursors.Arrow
  490.         End If
  491.         MyBase.OnMouseMove(e)
  492.         Invalidate()
  493.     End Sub
  494.  
  495. #End Region
  496. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement