Awesome Metro Controls For VB.NET

I found a class that gives you some controls that are alike Metro controls :) , the controls that this theme has
Just add a new class and paste these codes below and debug your program and then check your toolbox for the awesome looking tools(metro tools)


'by mavamaarten
Public Class MetroSlideControl
    Inherits TabControl
    Dim OldIndex As Integer

    Private _Speed As Integer = 15
    Property Speed As Integer
        Get
            Return _Speed
        End Get
        Set(ByVal value As Integer)
            If value > 20 Or value < -20 Then
                MsgBox("Speed needs to be in between -20 and 20.")
            Else
                _Speed = value
            End If
        End Set
    End Property

    Sub New()
        SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.OptimizedDoubleBuffer Or ControlStyles.ResizeRedraw, True)
    End Sub

    Sub DrawPanel(ByVal Panel As Panel)
        Dim bitmap As New Bitmap(Panel.Width, Panel.Height)
        Panel.DrawToBitmap(bitmap, New Rectangle(0, 0, Panel.Width, Panel.Height))
        CreateGraphics.DrawImage(bitmap, New Point(0, 0))
    End Sub

    Sub DoAnimationScrollLeft(ByVal Control1 As Control, ByVal Control2 As Control)
        Dim G As Graphics = Control1.CreateGraphics()
        Dim P1 As New Bitmap(Control1.Width, Control1.Height)
        Dim P2 As New Bitmap(Control2.Width, Control2.Height)
        Control1.DrawToBitmap(P1, New Rectangle(0, 0, Control1.Width, Control1.Height))
        Control2.DrawToBitmap(P2, New Rectangle(0, 0, Control2.Width, Control2.Height))

        For Each c As Control In Control1.Controls
            c.Hide()
        Next

        Dim Slide As Integer = Control1.Width - (Control1.Width Mod _Speed)

        Dim a As Integer
        For a = 0 To Slide Step _Speed
            G.DrawImage(P1, New Rectangle(a, 0, Control1.Width, Control1.Height))
            G.DrawImage(P2, New Rectangle(a - Control2.Width, 0, Control2.Width, Control2.Height))
        Next
        a = Control1.Width
        G.DrawImage(P1, New Rectangle(a, 0, Control1.Width, Control1.Height))
        G.DrawImage(P2, New Rectangle(a - Control2.Width, 0, Control2.Width, Control2.Height))

        SelectedTab = Control2

        For Each c As Control In Control2.Controls
            c.Show()
        Next

        For Each c As Control In Control1.Controls
            c.Show()
        Next
    End Sub

    Protected Overrides Sub OnSelecting(ByVal e As System.Windows.Forms.TabControlCancelEventArgs)
        If OldIndex < e.TabPageIndex Then
            DoAnimationScrollRight(TabPages(OldIndex), TabPages(e.TabPageIndex))
        Else
            DoAnimationScrollLeft(TabPages(OldIndex), TabPages(e.TabPageIndex))
        End If
    End Sub

    Protected Overrides Sub OnDeselecting(ByVal e As System.Windows.Forms.TabControlCancelEventArgs)
        OldIndex = e.TabPageIndex
    End Sub

    Sub DoAnimationScrollRight(ByVal Control1 As Control, ByVal Control2 As Control)
        Dim G As Graphics = Control1.CreateGraphics()
        Dim P1 As New Bitmap(Control1.Width, Control1.Height)
        Dim P2 As New Bitmap(Control2.Width, Control2.Height)
        Control1.DrawToBitmap(P1, New Rectangle(0, 0, Control1.Width, Control1.Height))
        Control2.DrawToBitmap(P2, New Rectangle(0, 0, Control2.Width, Control2.Height))

        For Each c As Control In Control1.Controls
            c.Hide()
        Next

        Dim Slide As Integer = Control1.Width - (Control1.Width Mod _Speed)

        Dim a As Integer
        For a = 0 To -Slide Step -_Speed
            G.DrawImage(P1, New Rectangle(a, 0, Control1.Width, Control1.Height))
            G.DrawImage(P2, New Rectangle(a + Control2.Width, 0, Control2.Width, Control2.Height))
        Next
        a = Control1.Width
        G.DrawImage(P1, New Rectangle(a, 0, Control1.Width, Control1.Height))
        G.DrawImage(P2, New Rectangle(a + Control2.Width, 0, Control2.Width, Control2.Height))

        SelectedTab = Control2

        For Each c As Control In Control2.Controls
            c.Show()
        Next

        For Each c As Control In Control1.Controls
            c.Show()
        Next
    End Sub

    Public Sub NextPage()
        If SelectedIndex < TabPages.Count - 1 Then SelectedIndex += 1
    End Sub

    Public Sub PreviousPage()
        If SelectedIndex > 0 Then SelectedIndex -= 1
    End Sub

    Protected Overrides Sub WndProc(ByRef m As Message)
        If m.Msg = &H1328 Then
            m.Result = CType(1, IntPtr)
        Else
            MyBase.WndProc(m)
        End If
    End Sub

End Class

Public Class MetroPanel
    Inherits Panel

    Private _TitleText As String = "Title"
    Property Title As String
        Get
            Return _TitleText
        End Get
        Set(ByVal value As String)
            _TitleText = value
            Invalidate()
        End Set
    End Property

    Private _SubTitleText As String = "Subtitle"
    Property SubTitle As String
        Get
            Return _SubTitleText
        End Get
        Set(ByVal value As String)
            _SubTitleText = value
            Invalidate()
        End Set
    End Property

    Private _TitleFont As Font = New Font("Segoe UI Light", 16)
    Property TitleFont As Font
        Get
            Return _TitleFont
        End Get
        Set(ByVal value As Font)
            _TitleFont = value
        End Set
    End Property

    Private _SubTitleFont As Font = New Font("Segoe UI", 9)
    Property SubTitleFont As Font
        Get
            Return _SubTitleFont
        End Get
        Set(ByVal value As Font)
            _SubTitleFont = value
        End Set
    End Property

    Private _DrawBorders As Boolean
    Property DrawBorders As Boolean
        Get
            Return _DrawBorders
        End Get
        Set(ByVal value As Boolean)
            _DrawBorders = value
            Invalidate()
        End Set
    End Property

    Private _BorderColor As Color
    Property BorderColor As Color
        Get
            Return _BorderColor
        End Get
        Set(ByVal value As Color)
            _BorderColor = value
        End Set
    End Property

    Sub New()
        BackColor = Color.White
    End Sub

    Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
        Dim G As Graphics = e.Graphics
        G.Clear(BackColor)
        G.DrawString(_TitleText, _TitleFont, New SolidBrush(ForeColor), New Point(8, 5))
        G.DrawString(_SubTitleText, _SubTitleFont, New SolidBrush(ForeColor), New Rectangle(12, 35, Width - 25, Height - 50))
        If DrawBorders Then
            G.DrawRectangle(New Pen(_BorderColor), New Rectangle(0, 0, Width - 1, Height - 1))
        End If
        MyBase.OnPaint(e)
    End Sub

End Class

Public Class MetroButton
    Inherits Control
    Enum MouseState
        None = 0
        Over = 1
        Down = 2
    End Enum
    Private State As MouseState = MouseState.None

    Dim _BGOver As Color '= Color.FromArgb(75, 75, 75)
    Property BackColorOver As Color
        Get
            Return _BGOver
        End Get
        Set(ByVal value As Color)
            _BGOver = value
            Invalidate()
        End Set
    End Property

    Dim _BGDown As Color '= Color.FromArgb(55, 55, 55)
    Property BackColorDown As Color
        Get
            Return _BGDown
        End Get
        Set(ByVal value As Color)
            _BGDown = value
            Invalidate()
        End Set
    End Property

    Dim _BorderColor As Color
    Property BorderColor As Color
        Get
            Return _BorderColor
        End Get
        Set(ByVal value As Color)
            _BorderColor = value
            Invalidate()
        End Set
    End Property


    Dim BGC As Color
    Property BackColorNormal As Color
        Get
            Return BGC
        End Get
        Set(ByVal value As Color)
            BGC = value
        End Set
    End Property

    Sub New()
        ForeColor = Color.White
        Font = New Font("Segoe UI", 9)
        SetStyle(ControlStyles.OptimizedDoubleBuffer, True)
        DoubleBuffered = True

        Dim R, G, B As Integer
        Dim BG As Color = BackColor

        R = BG.R - 20
        G = BG.G - 20
        B = BG.B - 20

        If R < 0 Then R = 0
        If G < 0 Then G = 0
        If B < 0 Then B = 0

        BGC = Color.FromArgb(R, G, B)

        Size = New Size(105, 27)
    End Sub

    Protected Overrides Sub OnBackColorChanged(ByVal e As System.EventArgs)
        Dim R, G, B As Integer

        R = BackColor.R - 20
        G = BackColor.G - 20
        B = BackColor.B - 20

        If R < 0 Then R = 0
        If G < 0 Then G = 0
        If B < 0 Then B = 0

        BGC = Color.FromArgb(R, G, B)

        R = BGC.R - 10
        G = BGC.G - 10
        B = BGC.B - 10

        If R < 0 Then R = 0
        If G < 0 Then G = 0
        If B < 0 Then B = 0

        _BGDown = Color.FromArgb(R, G, B)

        R = BGC.R + 10
        G = BGC.G + 10
        B = BGC.B + 10

        If R > 255 Then R = 255
        If G > 255 Then G = 255
        If B > 255 Then B = 255

        _BGOver = Color.FromArgb(R, G, B)

        R = BGC.R - 50
        G = BGC.G - 50
        B = BGC.B - 50

        If R < 0 Then R = 0
        If G < 0 Then G = 0
        If B < 0 Then B = 0

        _BorderColor = Color.FromArgb(R, G, B)
        MyBase.OnBackColorChanged(e)
    End Sub

    Protected Overrides Sub OnMouseEnter(ByVal e As System.EventArgs)
        State = MouseState.Over
        Invalidate()
        MyBase.OnMouseEnter(e)
    End Sub

    Protected Overrides Sub OnMouseLeave(ByVal e As System.EventArgs)
        State = MouseState.None
        Invalidate()
        MyBase.OnMouseLeave(e)
    End Sub

    Protected Overrides Sub OnMouseDown(ByVal e As System.Windows.Forms.MouseEventArgs)
        State = MouseState.Down
        Invalidate()
        MyBase.OnMouseDown(e)
    End Sub

    Protected Overrides Sub OnMouseUp(ByVal e As System.Windows.Forms.MouseEventArgs)
        State = MouseState.Over
        Invalidate()
        MyBase.OnMouseUp(e)
    End Sub

    Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
        Dim G As Graphics = e.Graphics
        Select Case State
            Case MouseState.None
                G.Clear(BGC)
            Case MouseState.Over
                G.Clear(BackColorOver)
            Case MouseState.Down
                G.Clear(BackColorDown)
        End Select
        G.DrawRectangle(New Pen(_BorderColor), New Rectangle(0, 0, Width - 1, Height - 1))
        Dim SF As New StringFormat : SF.Alignment = StringAlignment.Center : SF.LineAlignment = StringAlignment.Center
        G.DrawString(Text, Font, New SolidBrush(ForeColor), New Rectangle(0, 0, Width - 1, Height - 1), SF)
        MyBase.OnPaint(e)
    End Sub

End Class

Public Class MetroTextBox
    Inherits Control

    Private _TextAlign As HorizontalAlignment = HorizontalAlignment.Left
    Property TextAlign() As HorizontalAlignment
        Get
            Return _TextAlign
        End Get
        Set(ByVal value As HorizontalAlignment)
            _TextAlign = value
            If Base IsNot Nothing Then
                Base.TextAlign = value
            End If
        End Set
    End Property
    Private _MaxLength As Integer = 32767
    Property MaxLength() As Integer
        Get
            Return _MaxLength
        End Get
        Set(ByVal value As Integer)
            _MaxLength = value
            If Base IsNot Nothing Then
                Base.MaxLength = value
            End If
        End Set
    End Property
    Private _ReadOnly As Boolean
    Property [ReadOnly]() As Boolean
        Get
            Return _ReadOnly
        End Get
        Set(ByVal value As Boolean)
            _ReadOnly = value
            If Base IsNot Nothing Then
                Base.ReadOnly = value
            End If
        End Set
    End Property
    Private _UseSystemPasswordChar As Boolean
    Property UseSystemPasswordChar() As Boolean
        Get
            Return _UseSystemPasswordChar
        End Get
        Set(ByVal value As Boolean)
            _UseSystemPasswordChar = value
            If Base IsNot Nothing Then
                Base.UseSystemPasswordChar = value
            End If
        End Set
    End Property
    Private _Multiline As Boolean
    Property Multiline() As Boolean
        Get
            Return _Multiline
        End Get
        Set(ByVal value As Boolean)
            _Multiline = value
            If Base IsNot Nothing Then
                Base.Multiline = value

                If value Then
                    Base.Height = Height - 11
                Else
                End If
            End If
        End Set
    End Property
    Overrides Property Text As String
        Get
            Return MyBase.Text
        End Get
        Set(ByVal value As String)
            MyBase.Text = value
            If Base IsNot Nothing Then
                Base.Text = value
            End If
        End Set
    End Property
    Overrides Property Font As Font
        Get
            Return MyBase.Font
        End Get
        Set(ByVal value As Font)
            MyBase.Font = value
            If Base IsNot Nothing Then
                Base.Font = value
                Base.Location = New Point(3, 5)
                Base.Width = Width - 6
            End If
        End Set
    End Property

    Protected Overrides Sub OnParentChanged(ByVal e As System.EventArgs)
        If Not Controls.Contains(Base) Then
            Controls.Add(Base)
        End If
    End Sub

    Private Base As TextBox
    Dim C As Color
    Sub New()
        Font = New Font("Segoe UI", 9)
        Base = New TextBox
        Base.Font = Font
        Base.Text = Text
        Base.MaxLength = _MaxLength
        Base.Multiline = _Multiline
        Base.ReadOnly = _ReadOnly
        Base.UseSystemPasswordChar = _UseSystemPasswordChar
        Base.BorderStyle = BorderStyle.None
        Base.Location = New Point(5, 4)
        Base.Width = Width - 10

        If _Multiline Then
            Base.Height = Height - 11
        End If

        AddHandler Base.TextChanged, AddressOf OnBaseTextChanged
        AddHandler Base.KeyDown, AddressOf OnBaseKeyDown

        Dim R, G, B As Integer

        R = BackColor.R - 15
        G = BackColor.G - 15
        B = BackColor.B - 15

        If R < 0 Then R = 0
        If G < 0 Then G = 0
        If B < 0 Then B = 0

        C = Color.FromArgb(R, G, B)
        Base.BackColor = C
    End Sub

    Protected Overrides Sub OnBackColorChanged(ByVal e As System.EventArgs)
        MyBase.OnBackColorChanged(e)
        Dim R, G, B As Integer

        R = BackColor.R - 15
        G = BackColor.G - 15
        B = BackColor.B - 15

        If R < 0 Then R = 0
        If G < 0 Then G = 0
        If B < 0 Then B = 0

        C = Color.FromArgb(R, G, B)
        Base.BackColor = C
        Invalidate()
    End Sub

    Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
        Dim GG As Graphics = e.Graphics

        GG.Clear(C)
        GG.DrawRectangle(Pens.Black, New Rectangle(0, 0, Width - 1, Height - 1))
    End Sub
    Private Sub OnBaseTextChanged(ByVal s As Object, ByVal e As EventArgs)
        Text = Base.Text
    End Sub
    Private Sub OnBaseKeyDown(ByVal s As Object, ByVal e As KeyEventArgs)
        If e.Control AndAlso e.KeyCode = Keys.A Then
            Base.SelectAll()
            e.SuppressKeyPress = True
        End If
    End Sub
    Protected Overrides Sub OnResize(ByVal e As EventArgs)
        Base.Location = New Point(5, 4)
        Base.Width = Width - 10

        If _Multiline Then
            Base.Height = Height - 11
        End If


        MyBase.OnResize(e)
    End Sub

End Class

Public Class MetroProgressbar
    Inherits Control

    Dim _BorderColor As Color = Color.Black
    Property BorderColor As Color
        Get
            Return _BorderColor
        End Get
        Set(ByVal value As Color)
            _BorderColor = value
            Invalidate()
        End Set
    End Property

    Dim _ProgressColor As Color = Color.FromArgb(10, 150, 40)
    Property ProgressColor As Color
        Get
            Return _ProgressColor
        End Get
        Set(ByVal value As Color)
            _ProgressColor = value
            Invalidate()
        End Set
    End Property

    Sub New()
        SetStyle(ControlStyles.OptimizedDoubleBuffer Or ControlStyles.AllPaintingInWmPaint, True)
        DoubleBuffered = True
    End Sub

    Dim _Val As Integer = 0
    Property Value As Integer
        Get
            Return _Val
        End Get
        Set(ByVal v As Integer)
            If v <= _Max Then _Val = v Else Throw New Exception("The entered value is not valid.")
            Invalidate()
        End Set
    End Property

    Dim _Max As Integer = 100
    Property Maximum As Integer
        Get
            Return _Max
        End Get
        Set(ByVal value As Integer)
            If value >= _Val Then _Max = value Else Throw New Exception("The entered value is not valid.")
        End Set
    End Property

    Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
        Dim G As Graphics = e.Graphics
        Dim Progress As Double = (_Val / _Max) * (Width - 2)
        G.Clear(BackColor)
        G.FillRectangle(New SolidBrush(Color.FromArgb(20, Color.Black)), New Rectangle(0, 0, Width - 1, Height - 1))
        If Progress > 0 Then G.FillRectangle(New SolidBrush(_ProgressColor), New Rectangle(1, 1, Progress, Height - 2))

        G.DrawRectangle(New Pen(_BorderColor), New Rectangle(0, 0, Width - 1, Height - 1))
        MyBase.OnPaint(e)
    End Sub
End Class
here is a picture of the controls in my form

Post a Comment

Note: Only a member of this blog may post a comment.