Click here to Skip to main content
15,896,111 members
Articles / Desktop Programming / Windows Forms

Auto Flow Buttons Panel

Rate me:
Please Sign up or sign in to vote.
4.59/5 (11 votes)
26 Sep 2011CPOL5 min read 33.1K   1.4K   22  
A .NET control to control the layout of categorized sections in your application.
Imports System.Windows.Forms.Control
Imports System.Drawing
Imports System.Drawing.Drawing2D
Public Class YSSPAutoFlowButtonsPanel
    Public Class YSSPButton
        Inherits Button
        Public InnerPanel As New Panel
        Private m_Index As Integer
        '  Private DC As Graphics
        '  Private Shared m_Color1 As Color = PanelVariables.ButtonsColor1
        ' Private Shared m_Color2 As Color = PanelVariables.ButtonsColor2
        ' Private Shared GBrushP1 As New PointF(0, 0), GBrushP2 As New PointF(0, 32)
        ' Private Shared GBrushC1 As Color
        ' Private Shared GBrushC2 As Color
        ' Private Shared GBrush As Drawing.Drawing2D.LinearGradientBrush

        Public Sub New()
            InnerPanel.Top = Me.Bottom + 1
            InnerPanel.Left = Me.Left
            InnerPanel.Height = PanelVariables.PanelsHeight
            InnerPanel.Width = PanelVariables.PanelsWidth
            InnerPanel.BackColor = PanelVariables.PanelsBackColor

            If PanelVariables.ButtonsStyle = ButtonsStyle.Graphical Then
                If StateImages.MainImage Is Nothing Then Return
                Me.FlatStyle = Windows.Forms.FlatStyle.Flat
                Me.FlatAppearance.BorderSize = 0
                Me.BackgroundImageLayout = ImageLayout.Stretch
                Me.BackgroundImage = StateImages.MainImage
                ' ElseIf PanelVariables.ButtonsStyle = ButtonsStyle.Colors Then
                '  DC = Me.CreateGraphics()
                '  GBrushC1 = Color.FromArgb(200, PanelVariables.ButtonsColor1)
                '   GBrushC2 = Color.FromArgb(50, PanelVariables.ButtonsColor2)
                '  GBrush = New Drawing.Drawing2D.LinearGradientBrush(GBrushP1, GBrushP2, GBrushC1, GBrushC2)
            End If
        End Sub

        Public ReadOnly Property Index() As Integer
            Get
                Return m_Index
            End Get
        End Property
        Friend Property FriendIndex() As Integer
            Get
                Return m_Index
            End Get
            Set(ByVal value As Integer)
                m_Index = value
            End Set
        End Property

        Protected Overrides Sub OnParentChanged(ByVal e As System.EventArgs)
            MyBase.OnParentChanged(e)
            InnerPanel.Parent = Me.Parent ' change the innerpanel's parent to the button's parent
        End Sub
        Protected Overrides Sub OnLocationChanged(ByVal e As System.EventArgs)
            MyBase.OnLocationChanged(e)
            InnerPanel.Top = Me.Bottom + 1 ' every panel must be placed directly after its button
        End Sub
        Protected Overrides Sub OnSizeChanged(ByVal e As System.EventArgs)
            MyBase.OnSizeChanged(e)
            InnerPanel.Top = Me.Bottom + 1 ' every panel must be placed directly after its button
        End Sub

        Protected Overrides Sub OnMouseEnter(ByVal e As System.EventArgs)
            'return if this button is the selected one (Don't change its state)
            If PanelVariables.ButtonsStyle = ButtonsStyle.Graphical Then
                If PanelVariables.LayoutVeiw = LayoutVeiw.SingleVeiw Then
                    If PanelVariables.ButtonsStyle = ButtonsStyle.Graphical Then
                        If Me.InnerPanel.Visible = True Then
                            Exit Sub
                        End If
                    End If
                End If
                Me.BackgroundImage = StateImages.OverImage
                ' ElseIf PanelVariables.ButtonsStyle = ButtonsStyle.Colors Then
                '  Dim NDC As Graphics = Graphics.FromHwnd(Me.Handle)
                '    DC.DrawRectangle(Pens.Blue, New Rectangle(0, 0, 30, 30))
                ' NDC.FillRectangle(Brushes.Blue, New Rectangle(1, 1, 50, 50))
                'NDC.DrawString("UUUUUUUUUUUUUUUUUUUUUUUUUUUU", New Font("Arial", 20), Brushes.Black, 0, 0)
                '  NDC.Dispose()
            End If
            MyBase.OnMouseEnter(e)
        End Sub
        Protected Overrides Sub OnMouseLeave(ByVal e As System.EventArgs)
            MyBase.OnMouseLeave(e)
            If PanelVariables.ButtonsStyle = ButtonsStyle.Graphical Then
                'return if this button is the selected one (Don't change its state)
                If PanelVariables.ButtonsStyle = ButtonsStyle.Graphical Then
                    If PanelVariables.LayoutVeiw = LayoutVeiw.SingleVeiw Then
                        If PanelVariables.ButtonsStyle = ButtonsStyle.Graphical Then
                            If Me.InnerPanel.Visible = True Then
                                Exit Sub
                            End If
                        End If
                    End If
                End If
                Me.BackgroundImage = StateImages.MainImage
                ' ElseIf PanelVariables.ButtonsStyle = ButtonsStyle.Colors Then
                '   DC.Clear(Me.BackColor)
            End If

        End Sub
        Protected Overrides Sub OnMouseDown(ByVal mevent As System.Windows.Forms.MouseEventArgs)
            If PanelVariables.ButtonsStyle = ButtonsStyle.Graphical Then
                'return if this button is the selected one (Don't change its state)
                If PanelVariables.ButtonsStyle = ButtonsStyle.Graphical Then
                    If PanelVariables.LayoutVeiw = LayoutVeiw.SingleVeiw Then
                        If PanelVariables.ButtonsStyle = ButtonsStyle.Graphical Then
                            If Me.InnerPanel.Visible = True Then
                                Exit Sub
                            End If
                        End If
                    End If
                End If
                Me.BackgroundImage = StateImages.DownImage
                '   ElseIf PanelVariables.ButtonsStyle = ButtonsStyle.Colors Then
                '   DC.DrawRectangle(Pens.Blue, New Rectangle(0, 0, Me.Width, 20))
                '   DC.FillRectangle(GBrush, New Rectangle(1, 1, Me.Width - 1, Me.Height - 1))
            End If
            MyBase.OnMouseDown(mevent)
        End Sub
        Protected Overrides Sub OnMouseUp(ByVal mevent As System.Windows.Forms.MouseEventArgs)
            If PanelVariables.ButtonsStyle = ButtonsStyle.Graphical Then
                'return if this button is the selected one (Don't change its state)
                If PanelVariables.ButtonsStyle = ButtonsStyle.Graphical Then
                    If PanelVariables.LayoutVeiw = LayoutVeiw.SingleVeiw Then
                        If PanelVariables.ButtonsStyle = ButtonsStyle.Graphical Then
                            If Me.InnerPanel.Visible = True Then
                                Exit Sub
                            End If
                        End If
                    End If
                End If
                Me.BackgroundImage = StateImages.OverImage
                ' ElseIf PanelVariables.ButtonsStyle = ButtonsStyle.Colors Then
                '  DC.DrawRectangle(Pens.Blue, New Rectangle(0, 0, Me.Width, Me.Height))
                ' DC.FillRectangle(GBrush, New Rectangle(1, 1, Me.Width - 1, Me.Height - 1))
            End If
            MyBase.OnMouseUp(mevent)
        End Sub
        Protected Overrides Sub OnClick(ByVal e As System.EventArgs)
            MyBase.OnClick(e)
            ' if this button is the selected one set its background image to StateImages.SelecedImage image
            If PanelVariables.LayoutVeiw = LayoutVeiw.SingleVeiw Then
                If PanelVariables.ButtonsStyle = ButtonsStyle.Graphical Then
                    If Me.InnerPanel.Visible = True Then
                        Me.BackgroundImage = StateImages.SelecedImage
                    End If
                End If
            End If
        End Sub
    End Class

    Public NotInheritable Class YSSPAutoFlowButtonsPanel
        Inherits Panel

        Friend PreViewedButton As YSSPButton ' used in SingleVeiw style
        Friend InnerFlowButtons As New List(Of YSSPButton)
        Private _Settings As Settings = New Settings(Me)
        Private _ButtonsSettings As ButtonsSettings = New ButtonsSettings(Me)
        Private _PanelsSettings As PanelsSettings = New PanelsSettings(Me)
        Private _Buttons As Buttons = New Buttons(Me)
        Private _Panels = New Panels(Me)

        Public Sub New(ByVal Parent As Control)
            Me.Parent = Parent
            Me.Width = PanelVariables.Width
            Me.Height = PanelVariables.Height
            Me.Visible = True
            Me.AutoScroll = True
        End Sub
        Friend Sub ArrangeAll(ByVal sender As YSSPButton, ByVal e As System.EventArgs)
            If PanelVariables.LayoutVeiw = LayoutVeiw.MultiVewi Then
                Dim C As YSSPButton
                sender.InnerPanel.Visible = Not sender.InnerPanel.Visible
                sender.InnerPanel.Top = sender.Bottom + 1
                For I As Int16 = 1 To Buttons.Count - 1
                    C = InnerFlowButtons(I - 1)
                    If Not C Is Nothing Then
                        If C.InnerPanel.Visible = True Then
                            InnerFlowButtons(I).Top = C.InnerPanel.Bottom + 1 ' put the button after the previous button's panel
                        Else
                            InnerFlowButtons(I).Top = C.Bottom + 1 ' put the button after the previous button
                        End If
                    End If
                    InnerFlowButtons(I).InnerPanel.Top = InnerFlowButtons(I).Bottom + 1 ' every panel must be placed directly after its button
                Next
            Else
                If sender.InnerPanel.Visible = True Then Return ' in single view if current visible button is clicked there is no need to arrange all buttons
                Dim C As YSSPButton
                sender.InnerPanel.Visible = True ' to let the user see panel contents
                sender.InnerPanel.Top = sender.Bottom + 1 ' every panel must be placed directly after its button
                PreViewedButton.InnerPanel.Visible = False ' hide the panel of the previous viewed button
                PreViewedButton.InnerPanel.Top = sender.Bottom + 1 ' every panel must be placed directly after its button
                If PanelVariables.LayoutVeiw = WindowsApplication2.YSSPAutoFlowButtonsPanel.LayoutVeiw.SingleVeiw Then
                    If PanelVariables.ButtonsStyle = WindowsApplication2.YSSPAutoFlowButtonsPanel.ButtonsStyle.Graphical Then
                        PreViewedButton.BackgroundImage = StateImages.MainImage ' set the image of the previous viewed button to the main state image not the seleced state image
                    End If
                End If
                PreViewedButton = sender ' to be used in the next call

                For I As Int16 = 1 To Buttons.Count - 1
                    C = InnerFlowButtons(I - 1)
                    If Not C Is Nothing Then
                        If C.InnerPanel.Visible = True Then
                            InnerFlowButtons(I).Top = C.InnerPanel.Bottom + 1 ' put the button after the previous button's panel
                        Else
                            InnerFlowButtons(I).Top = C.Bottom + 1 ' put the button after the previous button
                        End If
                    End If
                    InnerFlowButtons(I).InnerPanel.Top = InnerFlowButtons(I).Bottom + 1 ' every panel must be placed directly after its button
                Next
            End If
        End Sub

        Public ReadOnly Property Settings() As Settings
            Get
                Return _Settings
            End Get
            '  Set(ByVal value As Settings)
            '   _Settings = value
            '     Me.Width = _Settings.Width
            '   Me.Height = _Settings.Height
            '   Me.BackColor = _Settings.BackColor
            '   Me.Left = _Settings.Left
            '  Me.Top = _Settings.Top
            '   Me.RightToLeft = _Settings.RightToLeft

            '  PanelVariables.Width = _Settings.Width
            '  PanelVariables.Height = _Settings.Height
            ' PanelVariables.BackColor = _Settings.BackColor
            '  PanelVariables.Left = _Settings.Left
            ' PanelVariables.Top = _Settings.Top
            ' PanelVariables.RightToLeft = _Settings.RightToLeft
            ' PanelVariables.LayoutVeiw = _Settings.LayoutVeiw
            ' PanelVariables.ButtonsStyle = _Settings.ButtonsStyle

            '  End Set
        End Property
        Public ReadOnly Property ButtonsSettings() As ButtonsSettings
            Get
                Return _ButtonsSettings
            End Get
            'Set(ByVal value As ButtonsSettings)
            '    _ButtonsSettings = value

            'Private _Font As Font
            '  Private _Cursor As Cursor
            ' Private _ForeColor As Color
            ' Private _BackColor As Color
            ' Private _Width As Integer
            ' Private _Height As Integer
            ' Private _Left As Integer
            ' Private _RightToLeft As RightToLeft
            ' Private _ImageAlign As Drawing.ContentAlignment
            'Private _ImageIndex As Integer
            ' Private _ImageKey As String
            ' Private _ImageList As ImageList
            ' Private _TextAlign As ContentAlignment
            ' 'Private _TextImageRelation As TextImageRelation
            ' Private _Parent As YSSPAutoFlowButtonsPanel
            '  End Set
        End Property
        Public ReadOnly Property PanelsSettings() As PanelsSettings
            Get
                Return _PanelsSettings
            End Get
            ' Set(ByVal value As PanelsSettings)
            '     _PanelsSettings = value
            ' End Set
        End Property

        Public ReadOnly Property Buttons() As Buttons
            Get
                Return _Buttons
            End Get
            '   Set(ByVal value As Buttons)
            '   _Buttons = value
            '  End Set
        End Property
        Public ReadOnly Property Panels() As Panels
            Get
                Return _Panels
            End Get
            '   Set(ByVal value As Panels)
            '       _Panels = value
            '   End Set
        End Property
        Public Sub ReArrange()
            ArrangeAll(InnerFlowButtons(0), New EventArgs)
        End Sub

    End Class

    Private Class PanelVariables
        ' this class contains general information that can be applied to all
        ' inner panels and buttons and these settings are used to add new buttons and inner panels with the same style of the other
        ' buttons and panels inside the main panel
        '-----------------------------------------------------------------------'
        '                   Main Panel Settings                                    '
        '-----------------------------------------------------------------------'
        Public Shared Height As Integer = 300 ' default main panel height
        Public Shared Width As Integer = 200 ' default main panel width
        Public Shared Left As Integer ' default main panel left
        Public Shared Top As Integer ' default main panel top

        Public Shared LayoutVeiw As LayoutVeiw = LayoutVeiw.SingleVeiw
        Public Shared ButtonsStyle As ButtonsStyle = ButtonsStyle.System

        Public Shared BackColor As Color ' default main panel back color

        Public Shared RightToLeft As RightToLeft ' default main panel dir

        '-----------------------------------------------------------------------'
        '                   Buttons Settings                                    '
        '-----------------------------------------------------------------------'

        ' default buttons settings
        Public Shared ButtonsLeft As Integer = 0
        Public Shared ButtonsWidth As Integer = 180
        Public Shared ButtonsHeight As Integer = 20

        Public Shared ButtonsBackColor As Color
        Public Shared ButtonsForeColor As Color

        Public Shared ButtonsFont As Font
        Public Shared ButtonsCursor As Cursor

        Public Shared ButtonsRightToLeft As RightToLeft

        Public Shared ButtonsImageAlign As ContentAlignment
        Public Shared ButtonsImageIndex As Integer
        Public Shared ButtonsImageKey As String
        Public Shared ButtonsImageList As ImageList

        Public Shared ButtonsTextAlign As ContentAlignment
        Public Shared ButtonsTextImageRelation As TextImageRelation

        ' Public Shared ButtonsColor1 As Color = Color.White
        '  Public Shared ButtonsColor2 As Color = Color.Blue
        ' Public Shared ButtonsColor3 As Color = Color.DodgerBlue ' Selected Button back color

        '-----------------------------------------------------------------------'
        '                   Inner Panels Settings                                    '
        '-----------------------------------------------------------------------'
        ' default panels settings
        Public Shared PanelsLeft As Integer = 0 ' inner panels left
        Public Shared PanelsWidth As Integer = 180  ' inner panels width
        Public Shared PanelsHeight As Integer = 50  ' inner panels height

        Public Shared PanelsBackgroundImage As Image
        Public Shared PanelsBackgroundImageLayout As Windows.Forms.ImageLayout

        Public Shared PanelsCursor As Cursor

        Public Shared PanelsForeColor As Color
        Public Shared PanelsBackColor As Color ' inner panels backcolor

        Public Shared PanelsRightToLeft As RightToLeft

    End Class

    Public Class Buttons
        ' this class is used to apply the following settings to an individual buttons
        ' if you want to apply a setting to all buttons
        ' you can make it using ButtonsSettings class

        Dim _Parent As YSSPAutoFlowButtonsPanel

        Public Sub New(ByVal Parent As YSSPAutoFlowButtonsPanel)
            _Parent = Parent
        End Sub

        Public Sub Add(ByVal Button As YSSPButton)
            If _Parent.Buttons.Count > 0 Then
                Button.FriendIndex = _Parent.Buttons.Count
                Button.Top = _Parent.InnerFlowButtons(_Parent.Buttons.Count - 1).InnerPanel.Bottom + 1
                Button.Left = PanelVariables.ButtonsLeft
                Button.Width = PanelVariables.ButtonsWidth
                Button.Height = PanelVariables.ButtonsHeight

                If PanelVariables.LayoutVeiw = LayoutVeiw.SingleVeiw Then
                    If _Parent.Buttons.Count = 1 Then
                        Button.Top = _Parent.InnerFlowButtons(_Parent.Buttons.Count - 1).InnerPanel.Bottom + 1
                    Else
                        Button.Top = _Parent.InnerFlowButtons(_Parent.Buttons.Count - 1).Bottom + 1
                    End If
                    Button.InnerPanel.Visible = False
                End If

                AddHandler Button.Click, AddressOf _Parent.ArrangeAll
                _Parent.InnerFlowButtons.Add(Button)
                _Parent.Controls.Add(Button)
            Else
                Button.FriendIndex = 0
                Button.Top = 0
                Button.Left = PanelVariables.ButtonsLeft
                Button.Width = PanelVariables.ButtonsWidth
                Button.Height = PanelVariables.ButtonsHeight
                AddHandler Button.Click, AddressOf _Parent.ArrangeAll
                _Parent.InnerFlowButtons.Add(Button)
                'If m_LayoutVeiw = LayoutVeiw.SingleVeiw Then Button.InnerPanel.Visible = False ' First button well be open automaticly for first veiw
                _Parent.PreViewedButton = Button
                _Parent.Controls.Add(Button)
            End If

        End Sub

        ' these methods are not tested or debuged yet
        Public Sub Remove(ByVal index As Integer)
            _Parent.InnerFlowButtons.RemoveAt(index)
        End Sub
        Public Sub Remove(ByVal Button As YSSPButton)
            _Parent.InnerFlowButtons.Remove(Button)
        End Sub
        Public Sub Hide(ByVal Index As Integer)
            If Index > _Parent.Buttons.Count Then Return
            _Parent.InnerFlowButtons(Index).Hide()
            _Parent.ArrangeAll(_Parent.InnerFlowButtons(Index), New EventArgs)
        End Sub
        Public ReadOnly Property Count() As Integer
            Get
                Return _Parent.InnerFlowButtons.Count
            End Get
        End Property
        Public Sub SetWidth(ByVal Index As Integer, ByVal Width As Integer)
            If Index > _Parent.Buttons.Count Then Return
            _Parent.InnerFlowButtons(Index).Width = Width
            _Parent.ArrangeAll(_Parent.InnerFlowButtons(Index), New EventArgs)
        End Sub
        Public Sub SetHeight(ByVal Index As Integer, ByVal Height As Integer)
            If Index > _Parent.Buttons.Count Then Return
            _Parent.InnerFlowButtons(Index).Height = Height
            _Parent.ArrangeAll(_Parent.InnerFlowButtons(Index), New EventArgs)
            ' _Parent.InnerFlowButtons.Item(Index).Height = Height
            ' _Parent.InnerFlowButtons.Item(0).InnerPanel.Visible = False
            ' _Parent.PreViewedButton = _Parent.InnerFlowButtons.Item(1)
            ' _Parent.ArrangeAll(_Parent.InnerFlowButtons.Item(0), New EventArgs)
        End Sub
        Public Sub Insert(ByVal Index As Integer, ByVal Button As YSSPButton)
            _Parent.InnerFlowButtons.Insert(Index, Button)
        End Sub
        Public Sub InsertRange(ByVal Start As Integer, ByVal Buttons As List(Of YSSPButton))
            _Parent.InnerFlowButtons.InsertRange(Start, Buttons)
        End Sub

        Public Sub Clear()
            _Parent.Controls.Clear()
            _Parent.Buttons.Clear()
        End Sub

    End Class

    Public Class Panels
        ' this class is used to apply the following settings to an individual panel
        ' if you want to apply a setting to all panels
        ' you can make it using PanelsSettings class
        Dim _Parent As YSSPAutoFlowButtonsPanel

        ' these methods are not tested or debuged yet
        Public Sub New(ByVal Parent As YSSPAutoFlowButtonsPanel)
            _Parent = Parent
        End Sub

        Public Sub SetPanelWidth(ByVal Index As Integer, ByVal Width As Integer)
            If Index > _Parent.Buttons.Count Or Index < 0 Then Return
            '_Parent.InnerFlowButtons.Item(Index).InnerPanel.Width = Width
            '_Parent.InnerFlowButtons.Item(0).InnerPanel.Visible = False ' to start arranging from the first buttin
            ' _Parent.PreViewedButton = _Parent.InnerFlowButtons.Item(1)
            ' _Parent.ArrangeAll(_Parent.InnerFlowButtons.Item(0), New EventArgs)
            _Parent.InnerFlowButtons(Index).InnerPanel.Width = Width
            _Parent.ArrangeAll(_Parent.InnerFlowButtons(Index), New EventArgs)
        End Sub
        Public Sub SetPanelHeight(ByVal Index As Integer, ByVal Height As Integer)
            If Index > _Parent.Buttons.Count Or Index < 0 Then Return
            '  _Parent.InnerFlowButtons.Item(Index).InnerPanel.Height = Height
            '  _Parent.InnerFlowButtons.Item(0).InnerPanel.Visible = False ' to start arranging from the first buttin
            ' _Parent.PreViewedButton = _Parent.InnerFlowButtons.Item(1)
            ' _Parent.ArrangeAll(_Parent.InnerFlowButtons.Item(0), New EventArgs)
            _Parent.InnerFlowButtons(Index).InnerPanel.Height = Height
            _Parent.ArrangeAll(_Parent.InnerFlowButtons(Index), New EventArgs)
        End Sub
    End Class

    Public Class ButtonsSettings
        ' this class is used to apply the following settings to all buttons
        ' if you want to apply a setting to an individual button
        ' you can do so using buttons class

        Private _Font As Font
        Private _Cursor As Cursor
        Private _ForeColor As Color
        Private _BackColor As Color
        Private _Width As Integer
        Private _Height As Integer
        Private _Left As Integer
        Private _RightToLeft As RightToLeft
        Private _ImageAlign As Drawing.ContentAlignment
        Private _ImageIndex As Integer
        Private _ImageKey As String
        Private _ImageList As ImageList
        Private _TextAlign As ContentAlignment
        Private _TextImageRelation As TextImageRelation
        Private _Parent As YSSPAutoFlowButtonsPanel

        Sub New(ByRef Parent As YSSPAutoFlowButtonsPanel)
            _Parent = Parent
        End Sub
        Public Property Font() As Font
            Get
                Return _Font
            End Get
            Set(ByVal value As Font)
                _Font = value
                PanelVariables.ButtonsFont = value
                For Each B As YSSPButton In _Parent.InnerFlowButtons
                    B.Font = value
                Next
            End Set
        End Property
        Public Property Cursor() As Windows.Forms.Cursor
            Get
                Return _Cursor
            End Get
            Set(ByVal value As Cursor)
                _Cursor = value
                If PanelVariables.ButtonsCursor = value Then Return
                PanelVariables.ButtonsCursor = value
                For Each B As YSSPButton In _Parent.InnerFlowButtons
                    B.Cursor = value
                Next
            End Set
        End Property
        Public Property ForeColor() As Color
            Get
                Return _ForeColor
            End Get
            Set(ByVal value As Color)
                _ForeColor = value
                If PanelVariables.ButtonsForeColor = value Then Return
                PanelVariables.ButtonsForeColor = value
                For Each B As YSSPButton In _Parent.InnerFlowButtons
                    B.ForeColor = value
                Next
            End Set
        End Property
        Public Property BackColor() As Color
            Get
                Return _BackColor
            End Get
            Set(ByVal value As Color)
                _BackColor = value
                If PanelVariables.ButtonsBackColor = value Then Return
                PanelVariables.ButtonsBackColor = value
                For Each B As YSSPButton In _Parent.InnerFlowButtons
                    B.BackColor = value
                Next
            End Set
        End Property
        Public Property Height() As Integer
            Get
                Return _Height
            End Get
            Set(ByVal value As Integer)
                _Height = value
                If PanelVariables.ButtonsHeight = value Then Return
                PanelVariables.ButtonsHeight = value
                For Each B As YSSPButton In _Parent.InnerFlowButtons
                    B.Height = value
                Next
            End Set
        End Property
        Public Property width() As Integer
            Get
                Return _Height
            End Get
            Set(ByVal value As Integer)
                _Width = value
                If PanelVariables.ButtonsWidth = value Then Return
                PanelVariables.ButtonsWidth = value
                For Each B As YSSPButton In _Parent.InnerFlowButtons
                    B.Width = value
                Next
            End Set
        End Property
        Public Property Left() As Integer
            Get
                Return _Left
            End Get
            Set(ByVal value As Integer)
                _Left = value
                If PanelVariables.ButtonsLeft = value Then Return
                PanelVariables.ButtonsLeft = value
                For Each B As YSSPButton In _Parent.InnerFlowButtons
                    B.Left = value
                Next
            End Set
        End Property
        Public Property RightToLeft() As RightToLeft
            Get
                Return _RightToLeft
            End Get
            Set(ByVal value As RightToLeft)
                _RightToLeft = value
                If PanelVariables.ButtonsRightToLeft = value Then Return
                PanelVariables.ButtonsRightToLeft = value
                For Each B As YSSPButton In _Parent.InnerFlowButtons
                    B.RightToLeft = value
                Next
            End Set
        End Property
        Public Property ImageAlign() As Drawing.ContentAlignment
            Get
                Return _ImageAlign
            End Get
            Set(ByVal value As ContentAlignment)
                _ImageAlign = value
                If PanelVariables.ButtonsImageAlign = value Then Return
                PanelVariables.ButtonsImageAlign = value
                For Each B As YSSPButton In _Parent.InnerFlowButtons
                    B.ImageAlign = value
                Next
            End Set
        End Property
        Public Property ImageIndex() As Integer
            Get
                Return _ImageIndex
            End Get
            Set(ByVal value As Integer)
                _ImageIndex = value
                If PanelVariables.ButtonsImageIndex = value Then Return
                PanelVariables.ButtonsImageIndex = value
                For Each B As YSSPButton In _Parent.InnerFlowButtons
                    B.ImageIndex = value
                Next
            End Set
        End Property
        Public Property ImageKey() As String
            Get
                Return _ImageKey
            End Get
            Set(ByVal value As String)
                _ImageKey = value
                If PanelVariables.ButtonsImageKey = value Then Return
                PanelVariables.ButtonsImageKey = value
                For Each B As YSSPButton In _Parent.InnerFlowButtons
                    B.ImageKey = value
                Next
            End Set
        End Property
        Public Property ImageList() As ImageList
            Get
                Return _ImageList
            End Get
            Set(ByVal value As ImageList)
                _ImageList = value
                If PanelVariables.ButtonsImageList.Handle = value.Handle Then Return
                PanelVariables.ButtonsImageList = value
                For Each B As YSSPButton In _Parent.InnerFlowButtons
                    B.ImageList = value
                Next
            End Set
        End Property
        Public Property TextAlign() As ContentAlignment
            Get
                Return _TextAlign
            End Get
            Set(ByVal value As ContentAlignment)
                _TextAlign = value
                If PanelVariables.ButtonsTextAlign = value Then Return
                PanelVariables.ButtonsTextAlign = value
                For Each B As YSSPButton In _Parent.InnerFlowButtons
                    B.TextAlign = value
                Next
            End Set
        End Property
        Public Property TextImageRelation() As TextImageRelation
            Get
                Return _TextImageRelation
            End Get
            Set(ByVal value As TextImageRelation)
                _TextImageRelation = value
                If PanelVariables.ButtonsTextImageRelation = value Then Return
                PanelVariables.ButtonsTextImageRelation = value
                For Each B As YSSPButton In _Parent.InnerFlowButtons
                    B.TextImageRelation = value
                Next
            End Set
        End Property

        Public Property MainImage() As Image
            Get
                Return StateImages.MainImage
            End Get
            Set(ByVal value As Image)
                StateImages.MainImage = value
                If PanelVariables.ButtonsStyle = WindowsApplication2.YSSPAutoFlowButtonsPanel.ButtonsStyle.Graphical Then
                    For Each B As YSSPButton In _Parent.InnerFlowButtons
                        B.BackgroundImage = value
                    Next
                End If
            End Set
        End Property
        Public Property OverImage() As Image
            Get
                Return StateImages.OverImage
            End Get
            Set(ByVal value As Image)
                StateImages.OverImage = value
            End Set
        End Property
        Public Property DownImage() As Image
            Get
                Return StateImages.DownImage
            End Get
            Set(ByVal value As Image)
                StateImages.DownImage = value
            End Set
        End Property
        Public Property SelectedImage() As Image
            Get
                Return StateImages.SelecedImage
            End Get
            Set(ByVal value As Image)
                StateImages.SelecedImage = value
                If PanelVariables.ButtonsStyle = WindowsApplication2.YSSPAutoFlowButtonsPanel.ButtonsStyle.Graphical Then
                    If PanelVariables.LayoutVeiw = WindowsApplication2.YSSPAutoFlowButtonsPanel.LayoutVeiw.SingleVeiw Then
                        _Parent.PreViewedButton.BackgroundImage = value
                    End If
                End If
            End Set
        End Property

    End Class

    Public Class PanelsSettings
        ' this class is used to apply the following settings to all panels
        ' if you want to apply a setting to an individual panel
        ' you can do so using panels class
        Private _BackgroundImage As Image
        Private _BackgroundImageLayout As Windows.Forms.ImageLayout
        Private _Cursor As Windows.Forms.Cursor
        Private _ForeColor As Color
        Private _BackColor As Color
        Private _Height As Integer
        Private _width As Integer
        Private _Left As Integer
        Private _RightToLeft As RightToLeft
        Private _Parent As YSSPAutoFlowButtonsPanel

        Sub New(ByRef Parent As YSSPAutoFlowButtonsPanel)
            _Parent = Parent
        End Sub
        Public Property BackgroundImage() As Image
            Get
                Return _BackgroundImage
            End Get
            Set(ByVal value As Image)
                _BackgroundImage = value
                PanelVariables.PanelsBackgroundImage = value
                For Each B As YSSPButton In _Parent.InnerFlowButtons
                    B.InnerPanel.BackgroundImage = value
                Next
            End Set
        End Property
        Public Property BackgroundImageLayout() As Windows.Forms.ImageLayout
            Get
                Return _BackgroundImageLayout
            End Get
            Set(ByVal value As Windows.Forms.ImageLayout)
                _BackgroundImageLayout = value
                If PanelVariables.PanelsBackgroundImageLayout = value Then Return
                PanelVariables.PanelsBackgroundImageLayout = value
                For Each B As YSSPButton In _Parent.InnerFlowButtons
                    B.InnerPanel.BackgroundImageLayout = value
                Next
            End Set
        End Property
        Public Property Cursor() As Windows.Forms.Cursor
            Get
                Return _Cursor
            End Get
            Set(ByVal value As Cursor)
                _Cursor = value
                If PanelVariables.PanelsCursor = value Then Return
                PanelVariables.PanelsCursor = value
                For Each B As YSSPButton In _Parent.InnerFlowButtons
                    B.InnerPanel.Cursor = value
                Next
            End Set
        End Property
        Public Property ForeColor() As Color
            Get
                Return _ForeColor
            End Get
            Set(ByVal value As Color)
                _ForeColor = value
                If PanelVariables.PanelsForeColor = value Then Return
                PanelVariables.PanelsForeColor = value
                For Each B As YSSPButton In _Parent.InnerFlowButtons
                    B.InnerPanel.ForeColor = value
                Next
            End Set
        End Property
        Public Property BackColor() As Color
            Get

            End Get
            Set(ByVal value As Color)
                _BackColor = value
                If PanelVariables.PanelsBackColor = value Then Return
                PanelVariables.PanelsBackColor = value
                For Each B As YSSPButton In _Parent.InnerFlowButtons
                    B.InnerPanel.BackColor = value
                Next
            End Set
        End Property
        Public Property Height() As Integer
            Get
                Return _Height
            End Get
            Set(ByVal value As Integer)
                _Height = value
                If PanelVariables.PanelsHeight = value Then Return
                PanelVariables.PanelsHeight = value
                For Each B As YSSPButton In _Parent.InnerFlowButtons
                    B.InnerPanel.Height = value
                Next
            End Set
        End Property
        Public Property width() As Integer
            Get
                Return _width
            End Get
            Set(ByVal value As Integer)
                _width = value
                If PanelVariables.PanelsWidth = value Then Return
                PanelVariables.PanelsWidth = value
                For Each B As YSSPButton In _Parent.InnerFlowButtons
                    B.InnerPanel.Width = value
                Next
            End Set
        End Property
        Public Property Left() As Integer
            Get
                Return _Left
            End Get
            Set(ByVal value As Integer)
                _Left = value
                If PanelVariables.PanelsLeft = value Then Return
                PanelVariables.PanelsLeft = value
                For Each B As YSSPButton In _Parent.InnerFlowButtons
                    B.InnerPanel.Left = value
                Next
            End Set
        End Property
        Public Property RightToLeft() As RightToLeft
            Get
                Return _RightToLeft
            End Get
            Set(ByVal value As RightToLeft)
                _RightToLeft = value
                If PanelVariables.PanelsRightToLeft = value Then Return
                PanelVariables.PanelsRightToLeft = value
                For Each B As YSSPButton In _Parent.InnerFlowButtons
                    B.InnerPanel.RightToLeft = value
                Next
            End Set
        End Property

    End Class

    Public Class Settings

        Private _Width As Integer
        Private _Height As Integer
        Private _BackColor As Color
        Private _Left As Integer
        Private _Top As Integer
        Private _RightToLeft As RightToLeft
        Private _LayoutVeiw As LayoutVeiw = LayoutVeiw.SingleVeiw
        Private _ButtonsStyle As ButtonsStyle = ButtonsStyle.System
        Private _Parent As YSSPAutoFlowButtonsPanel

        Sub New(ByRef Parent As YSSPAutoFlowButtonsPanel)
            _Parent = Parent
        End Sub
        Public Property LayoutVeiw() As LayoutVeiw
            Get
                Return _LayoutVeiw
            End Get
            Set(ByVal value As LayoutVeiw)
                _LayoutVeiw = value
                If PanelVariables.LayoutVeiw = value Then Return
                PanelVariables.LayoutVeiw = value

                If PanelVariables.ButtonsStyle = ButtonsStyle.Graphical Then
                    If PanelVariables.LayoutVeiw = LayoutVeiw.SingleVeiw Then
                        If Not _Parent.PreViewedButton Is Nothing Then _
                        _Parent.PreViewedButton.BackgroundImage = StateImages.MainImage
                    End If
                End If

                If value = LayoutVeiw.SingleVeiw Then
                    For Each B As YSSPButton In _Parent.InnerFlowButtons
                        B.InnerPanel.Visible = False
                    Next
                    _Parent.PreViewedButton = _Parent.InnerFlowButtons.Item(1)
                    _Parent.ArrangeAll(_Parent.InnerFlowButtons.Item(0), New EventArgs)
                End If
            End Set
        End Property
        Public Property ButtonsStyle() As ButtonsStyle
            Get
                Return _ButtonsStyle
            End Get
            Set(ByVal value As ButtonsStyle)
                _ButtonsStyle = value
                If PanelVariables.ButtonsStyle = value Then Return
                PanelVariables.ButtonsStyle = value
                If value = ButtonsStyle.Graphical Then
                    For Each B As YSSPButton In _Parent.InnerFlowButtons
                        B.BackgroundImage = StateImages.MainImage
                        B.BackgroundImageLayout = ImageLayout.Stretch
                        B.FlatStyle = Windows.Forms.FlatStyle.Flat
                        B.FlatAppearance.BorderSize = 0
                    Next
                Else
                    For Each B As YSSPButton In _Parent.InnerFlowButtons
                        B.BackgroundImage = Nothing
                        B.FlatStyle = Windows.Forms.FlatStyle.System
                        B.FlatAppearance.BorderSize = 1
                    Next
                End If
            End Set
        End Property
        Public Property Width() As Integer
            Get
                Return _Width
            End Get
            Set(ByVal value As Integer)
                _Width = value
                If PanelVariables.Width = value Then Return
                PanelVariables.Width = value
                _Parent.Width = value
            End Set

        End Property
        Public Property Height() As Integer
            Get
                Return _Height
            End Get
            Set(ByVal value As Integer)
                _Height = value
                If PanelVariables.Height = value Then Return
                PanelVariables.Height = value
                _Parent.Height = value
            End Set
        End Property
        Public Property BackColor() As Color
            Get
                Return _BackColor
            End Get
            Set(ByVal value As Color)
                _BackColor = value
                If PanelVariables.BackColor = value Then Return
                PanelVariables.BackColor = value
                _Parent.BackColor = value
            End Set
        End Property
        Public Property Left() As Integer
            Get
                Return _Left
            End Get
            Set(ByVal value As Integer)
                _Left = value
                If PanelVariables.Left = value Then Return
                PanelVariables.Left = value
                _Parent.Left = value
            End Set
        End Property
        Public Property Top() As Integer
            Get
                Return _Top
            End Get
            Set(ByVal value As Integer)
                _Top = value
                If PanelVariables.Top = value Then Return
                PanelVariables.Top = value
                _Parent.Top = value
            End Set
        End Property
        Public Property RightToLeft() As Boolean
            Get
                Return _RightToLeft
            End Get
            Set(ByVal value As Boolean)
                _RightToLeft = value
                If PanelVariables.RightToLeft = value Then Return
                PanelVariables.RightToLeft = value
                _Parent.RightToLeft = value
            End Set
        End Property


    End Class

    Private Class StateImages
        Public Shared MainImage As Image = My.Resources.Main
        Public Shared OverImage As Image = My.Resources.Over
        Public Shared DownImage As Image = My.Resources.Down
        Public Shared SelecedImage As Image = My.Resources.Selected
    End Class

    Public Enum LayoutVeiw
        SingleVeiw ' only one category can be viewed 
        MultiVewi ' many categories can be viewed at the same time
    End Enum

    Public Enum ButtonsStyle
        Graphical
        ' Colors ' not implemented yet
        System
    End Enum
End Class

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Egypt Egypt
I am a software and web developer using C#, C/C++, VB.NET, PHP

And a lot of other programs and technologies
I also have a good knowledge of Photoshop

My favorite hobby is writing application to solve any problems I face and to provide web community and computer users with a new helping solutions.

Comments and Discussions