Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'Random Controls: LoginBox
- 'By Nettro ;P
- Imports System.Drawing.Drawing2D
- Imports System.ComponentModel
- Public Class LoginBox
- Inherits Panel
- Event Clicked()
- Protected Overrides Sub OnCreateControl()
- MyBase.OnCreateControl()
- If Not Controls.Contains(TB) Then
- Controls.Add(TB)
- Controls.Add(TB2)
- End If
- End Sub
- #Region "Modules & Functions"
- Public Sub DrawRoundRect(g As Graphics, p As Pen, x As Single, y As Single, width As Single, height As Single, _
- radius As Single)
- Dim gp As New GraphicsPath()
- gp.AddLine(x + radius, y, x + width - (radius * 2), y)
- ' Line
- gp.AddArc(x + width - (radius * 2), y, radius * 2, radius * 2, 270, 90)
- ' Corner
- gp.AddLine(x + width, y + radius, x + width, y + height - (radius * 2))
- ' Line
- gp.AddArc(x + width - (radius * 2), y + height - (radius * 2), radius * 2, radius * 2, 0, 90)
- ' Corner
- gp.AddLine(x + width - (radius * 2), y + height, x + radius, y + height)
- ' Line
- gp.AddArc(x, y + height - (radius * 2), radius * 2, radius * 2, 90, 90)
- ' Corner
- gp.AddLine(x, y + height - (radius * 2), x, y + radius)
- ' Line
- gp.AddArc(x, y, radius * 2, radius * 2, 180, 90)
- ' Corner
- gp.CloseFigure()
- g.DrawPath(p, gp)
- gp.Dispose()
- End Sub
- Public Sub FillRoundedRectangle(ByVal g As Drawing.Graphics, ByVal r As Rectangle, ByVal d As Integer, ByVal b As Brush)
- Dim mode As Drawing2D.SmoothingMode = g.SmoothingMode
- g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality
- g.FillPie(b, r.X, r.Y, d, d, 180, 90)
- g.FillPie(b, r.X + r.Width - d, r.Y, d, d, 270, 90)
- g.FillPie(b, r.X, r.Y + r.Height - d, d, d, 90, 90)
- g.FillPie(b, r.X + r.Width - d, r.Y + r.Height - d, d, d, 0, 90)
- g.FillRectangle(b, CInt(r.X + d / 2), r.Y, r.Width - d, CInt(d / 2))
- g.FillRectangle(b, r.X, CInt(r.Y + d / 2), r.Width, CInt(r.Height - d))
- g.FillRectangle(b, CInt(r.X + d / 2), CInt(r.Y + r.Height - d / 2), CInt(r.Width - d), CInt(d / 2))
- g.SmoothingMode = mode
- End Sub
- Public Sub FillNotTopRoundedRectangle(ByVal g As Drawing.Graphics, ByVal r As Rectangle, ByVal d As Integer, ByVal b As Brush)
- Dim mode As Drawing2D.SmoothingMode = g.SmoothingMode
- g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality
- g.FillPie(b, r.X, r.Y, 1, 1, 180, 90)
- g.FillPie(b, r.X + r.Width - d, r.Y, 1, 1, 270, 90)
- g.FillPie(b, r.X, r.Y + r.Height - d, d, d, 90, 90)
- g.FillPie(b, r.X + r.Width - d, r.Y + r.Height - d, d, d, 0, 90)
- ' g.FillRectangle(b, CInt(r.X + d / 2), r.Y, r.Width - d, CInt(d / 2))
- g.FillRectangle(b, r.X, CInt(r.Y + d / 2), r.Width, CInt(r.Height - d))
- g.FillRectangle(b, CInt(r.X + d / 2), CInt(r.Y + r.Height - d / 2), CInt(r.Width - d), CInt(d / 2))
- g.SmoothingMode = mode
- End Sub
- #End Region
- Sub New()
- Me.Size = New Size(234, 178)
- SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.UserPaint Or _
- ControlStyles.ResizeRedraw Or ControlStyles.OptimizedDoubleBuffer Or _
- ControlStyles.SupportsTransparentBackColor, True)
- DoubleBuffered = True
- BackColor = Color.Transparent
- Parent = FindForm()
- 'Textbox 1
- MyBase.Font = New Font("Arial", 12, FontStyle.Regular)
- TB = New Windows.Forms.TextBox
- TB.BackColor = _BaseColour
- TB.Font = New Font("Segoe UI", 9)
- TB.Text = Text
- TB.BackColor = _BaseColour
- TB.ForeColor = _TextColour
- TB.MaxLength = _MaxLength
- TB.Multiline = False
- TB.ReadOnly = _ReadOnly
- TB.UseSystemPasswordChar = _UseSystemPasswordChar
- TB.BorderStyle = BorderStyle.None
- TB.Location = New Point(20, 20)
- TB.Width = Width - 10
- TB.Font = MyBase.Font
- 'Textbox2
- TB2 = New Windows.Forms.TextBox
- TB2.BackColor = _BaseColour
- TB2.Font = New Font("Segoe UI", 9)
- TB2.Text = Text
- TB2.BackColor = _BaseColour
- TB2.ForeColor = _TextColour
- TB2.MaxLength = _MaxLength
- TB2.Multiline = False
- TB2.ReadOnly = _ReadOnly
- TB2.UseSystemPasswordChar = _UseSystemPasswordChar
- TB2.BorderStyle = BorderStyle.None
- TB2.Location = New Point(20, 85)
- TB2.Width = Width - 10
- TB2.Font = MyBase.Font
- End Sub
- #Region "paint"
- Private Sub LoginBox_Paint(sender As Object, e As PaintEventArgs) Handles Me.Paint
- e.Graphics.SmoothingMode = SmoothingMode.AntiAlias
- Dim Rect = New Rectangle(0, 0, Me.Width, Me.Height - 10)
- 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!)
- FillRoundedRectangle(e.Graphics, Rect, 18, GradBrush)
- ' DrawRoundRect(e.Graphics, New Pen(Color.FromArgb(240, 240, 240)), 0, 0, Me.Width, Me.Height, 18)
- If clickedd = False Then
- Rect = New Rectangle(0, Me.Height - 70, Me.Width, 70)
- GradBrush = New LinearGradientBrush(Rect, Color.FromArgb(147, 179, 201), Color.FromArgb(68, 93, 113), 90.0!)
- FillNotTopRoundedRectangle(e.Graphics, Rect, 18, GradBrush)
- Else
- Rect = New Rectangle(0, Me.Height - 70, Me.Width, 70)
- GradBrush = New LinearGradientBrush(Rect, Color.FromArgb(68, 93, 113), Color.FromArgb(48, 73, 93), 90.0!)
- FillNotTopRoundedRectangle(e.Graphics, Rect, 18, GradBrush)
- End If
- GradBrush = New LinearGradientBrush(Rect, Color.FromArgb(50, Color.Black), Color.FromArgb(147, 179, 201), 90.0!)
- Rect = New Rectangle(0, Me.Height - 64, Me.Width, 4)
- e.Graphics.FillRectangle(GradBrush, Rect)
- e.Graphics.DrawLine(New Pen(Color.FromArgb(191, 191, 191)), New Point(0, 60), New Point(Me.Width, 60))
- e.Graphics.FillRectangle(New SolidBrush(Color.FromArgb(240, 240, 240)), New Rectangle(6, 0, 5, 10))
- e.Graphics.FillRectangle(New SolidBrush(Color.FromArgb(240, 240, 240)), New Rectangle(Me.Width - 10, 0, 5, 5))
- e.Graphics.FillRectangle(New SolidBrush(Color.FromArgb(240, 240, 240)), New Rectangle(0, 5, Me.Width, 10))
- 'Fix Bottom
- If clickedd = False Then
- e.Graphics.FillRectangle(New SolidBrush(Color.FromArgb(77, 103, 123)), New Rectangle(8, Me.Height - 8, 2, 7))
- e.Graphics.FillRectangle(New SolidBrush(Color.FromArgb(77, 103, 123)), New Rectangle(Me.Width - 10, Me.Height - 8, 2, 7))
- e.Graphics.FillRectangle(New SolidBrush(Color.FromArgb(77, 103, 123)), New Rectangle(0, Me.Height - 10, Me.Width, 2))
- Else
- e.Graphics.FillRectangle(New SolidBrush(Color.FromArgb(48, 73, 93)), New Rectangle(8, Me.Height - 8, 2, 7))
- e.Graphics.FillRectangle(New SolidBrush(Color.FromArgb(48, 73, 93)), New Rectangle(Me.Width - 10, Me.Height - 8, 2, 7))
- e.Graphics.FillRectangle(New SolidBrush(Color.FromArgb(48, 73, 93)), New Rectangle(0, Me.Height - 10, Me.Width, 2))
- End If
- If clickedd = False Then
- If New Rectangle(10, Me.Height - 60, Me.Width - 20, 70).Contains(mouseX, mouseY) Then
- 'e.Graphics.FillEllipse(New SolidBrush(Color.FromArgb(50, Color.White)), New Rectangle(mouseX - 7, mouseY - 7, 14, 14))
- 'e.Graphics.FillEllipse(New SolidBrush(Color.FromArgb(60, Color.White)), New Rectangle(mouseX - 8, mouseY - 8, 16, 16))
- 'e.Graphics.FillEllipse(New SolidBrush(Color.FromArgb(70, Color.White)), New Rectangle(mouseX - 10, mouseY - 10, 20, 20))
- 'e.Graphics.FillEllipse(New SolidBrush(Color.FromArgb(100, Color.White)), New Rectangle(mouseX - 3, mouseY - 3, 5, 5))
- 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})
- 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})
- End If
- End If
- DrawRoundRect(e.Graphics, New Pen(Color.FromArgb(44, 44, 44)), 1, 1, Me.Width - 3, Me.Height - 3, 4)
- 'Textboxs
- TB.Text = TB.Text
- TB.BackColor = _BaseColour
- TB.ForeColor = _TextColour
- TB.Location = New Point(20, 20)
- TB.Width = Width - 40
- TB2.Text = TB2.Text
- TB2.BackColor = _BaseColour2
- TB2.ForeColor = _TextColour2
- TB2.Location = New Point(20, 85)
- TB2.Width = Width - 40
- 'Sign In
- 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})
- clickedd = False
- End Sub
- #End Region
- #Region "Properties & Events"
- Public WithEvents TB2 As TextBox
- Public WithEvents TB As New TextBox
- Private _BaseColour As Color = Color.FromArgb(236, 233, 234)
- Private _BorderColour As Color = Color.FromArgb(163, 190, 146)
- Private _LineColour As Color = Color.FromArgb(221, 221, 221)
- Private _TextColour As Color = Color.FromArgb(149, 147, 148)
- Private _TextAlign As HorizontalAlignment = HorizontalAlignment.Left
- Private _MaxLength As Integer = 32767
- Private _ReadOnly As Boolean
- Private _UseSystemPasswordChar As Boolean
- Private _Text As String = "Username"
- Private _Text2 As String = "Password"
- Private _BaseColour2 As Color = Color.FromArgb(218, 213, 211)
- Private _BorderColour2 As Color = Color.FromArgb(163, 190, 146)
- Private _LineColour2 As Color = Color.FromArgb(221, 221, 221)
- Private _TextColour2 As Color = Color.FromArgb(149, 147, 148)
- Private _TextAlign2 As HorizontalAlignment = HorizontalAlignment.Left
- Private _MaxLength2 As Integer = 32767
- Private _ReadOnly2 As Boolean
- Private _UseSystemPasswordChar2 As Boolean
- Private _Multiline As Boolean
- Public Sub SelectAll()
- TB.Focus()
- TB.SelectAll()
- Invalidate()
- End Sub
- <Category("Username")>
- Public Property BaseColour As Color
- Get
- Return _BaseColour
- End Get
- Set(value As Color)
- _BaseColour = value
- End Set
- End Property
- <Category("Username")>
- Public Property BorderColour As Color
- Get
- Return _BorderColour
- End Get
- Set(value As Color)
- _BorderColour = value
- End Set
- End Property
- <Category("Username")>
- Public Property LineColour As Color
- Get
- Return _LineColour
- End Get
- Set(value As Color)
- _LineColour = value
- End Set
- End Property
- <Category("Username")>
- Public Property TextColour As Color
- Get
- Return _TextColour
- End Get
- Set(value As Color)
- _TextColour = value
- End Set
- End Property
- <Category("Username")>
- Property TextAlign() As HorizontalAlignment
- Get
- Return _TextAlign
- End Get
- Set(ByVal value As HorizontalAlignment)
- _TextAlign = value
- If TB IsNot Nothing Then
- TB.TextAlign = value
- End If
- End Set
- End Property
- <Category("Username")>
- Property MaxLength() As Integer
- Get
- Return _MaxLength
- End Get
- Set(ByVal value As Integer)
- _MaxLength = value
- If TB IsNot Nothing Then
- TB.MaxLength = value
- End If
- End Set
- End Property
- <Category("Username")>
- Property [ReadOnly]() As Boolean
- Get
- Return _ReadOnly
- End Get
- Set(ByVal value As Boolean)
- _ReadOnly = value
- If TB IsNot Nothing Then
- TB.ReadOnly = value
- End If
- End Set
- End Property
- <Category("Username")>
- Property UseSystemPasswordChar() As Boolean
- Get
- Return _UseSystemPasswordChar
- End Get
- Set(ByVal value As Boolean)
- _UseSystemPasswordChar = value
- If TB IsNot Nothing Then
- TB.UseSystemPasswordChar = value
- End If
- End Set
- End Property
- <Category("Username")>
- Property Textt As String
- Get
- Return _Text
- End Get
- Set(ByVal value As String)
- _Text = value
- If TB IsNot Nothing Then
- TB.Text = value
- End If
- End Set
- End Property
- 'Password
- <Category("Password")>
- Property Text2 As String
- Get
- Return _Text2
- End Get
- Set(ByVal value As String)
- _Text = value
- If TB2 IsNot Nothing Then
- TB2.Text = value
- End If
- End Set
- End Property
- <Category("Password")>
- Public Property BaseColour2 As Color
- Get
- Return _BaseColour2
- End Get
- Set(value As Color)
- _BaseColour2 = value
- End Set
- End Property
- <Category("Password")>
- Public Property BorderColour2 As Color
- Get
- Return _BorderColour2
- End Get
- Set(value As Color)
- _BorderColour2 = value
- End Set
- End Property
- <Category("Password")>
- Public Property LineColour2 As Color
- Get
- Return _LineColour2
- End Get
- Set(value As Color)
- _LineColour2 = value
- End Set
- End Property
- <Category("Password")>
- Public Property TextColour2 As Color
- Get
- Return _TextColour2
- End Get
- Set(value As Color)
- _TextColour2 = value
- End Set
- End Property
- <Category("Password")>
- Property TextAlign2() As HorizontalAlignment
- Get
- Return _TextAlign2
- End Get
- Set(ByVal value As HorizontalAlignment)
- _TextAlign = value
- If TB2 IsNot Nothing Then
- TB2.TextAlign = value
- End If
- End Set
- End Property
- <Category("Password")>
- Property MaxLength2() As Integer
- Get
- Return _MaxLength2
- End Get
- Set(ByVal value As Integer)
- _MaxLength2 = value
- If TB2 IsNot Nothing Then
- TB2.MaxLength = value
- End If
- End Set
- End Property
- <Category("Password")>
- Property [ReadOnly2]() As Boolean
- Get
- Return _ReadOnly2
- End Get
- Set(ByVal value As Boolean)
- _ReadOnly2 = value
- If TB2 IsNot Nothing Then
- TB2.ReadOnly = value
- End If
- End Set
- End Property
- <Category("Password")>
- Property UseSystemPasswordChar2() As Boolean
- Get
- Return _UseSystemPasswordChar2
- End Get
- Set(ByVal value As Boolean)
- _UseSystemPasswordChar2 = value
- If TB2 IsNot Nothing Then
- TB2.UseSystemPasswordChar = value
- End If
- End Set
- End Property
- <Category("Password")>
- Overrides Property Text As String
- Get
- Return _Text2
- End Get
- Set(ByVal value As String)
- _Text2 = value
- If TB2 IsNot Nothing Then
- TB2.Text = value
- End If
- End Set
- End Property
- <Category("Control")>
- Overrides Property Font As Font
- Get
- Return MyBase.Font
- End Get
- Set(ByVal value As Font)
- MyBase.Font = value
- If TB2 IsNot Nothing Then
- TB2.Font = value
- TB2.Location = New Point(3, 5)
- TB2.Width = Width - 6
- TB.Font = value
- TB.Location = New Point(3, 5)
- TB.Width = Width - 6
- If Not _Multiline Then
- Height = TB.Height + 11
- End If
- End If
- End Set
- End Property
- Private Sub OnBaseTextChanged(ByVal s As Object, ByVal e As EventArgs)
- _Text = TB.Text
- _Text2 = TB2.Text
- End Sub
- Protected Overrides Sub OnResize(ByVal e As EventArgs)
- TB.Location = New Point(20, 20)
- TB.Width = Width - 10
- 'TB2.Location = New Point(85, 85)
- 'TB2.Width = Width - 10
- MyBase.OnResize(e)
- End Sub
- #End Region
- #Region "ThemeDraggable"
- Dim clickedd As Boolean = False
- Protected Overrides Sub OnMouseDown(e As MouseEventArgs)
- If New Rectangle(0, Me.Height - 60, Me.Width, 60).Contains(mouseX, mouseY) Then
- If e.Button = Windows.Forms.MouseButtons.Left Then
- RaiseEvent Clicked()
- clickedd = True
- End If
- End If
- '
- MyBase.OnMouseDown(e)
- End Sub
- Protected Overrides Sub OnMouseUp(e As MouseEventArgs)
- MyBase.OnMouseUp(e)
- End Sub
- Private mouseX As Integer
- Private mouseY As Integer
- Protected Overrides Sub OnMouseMove(e As MouseEventArgs)
- mouseX = e.X
- mouseY = e.Y
- If New Rectangle(0, Me.Height - 70, Me.Width, 70).Contains(mouseX, mouseY) Then
- Cursor = Cursors.Hand
- Else
- Cursor = Cursors.Arrow
- End If
- MyBase.OnMouseMove(e)
- Invalidate()
- End Sub
- #End Region
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement