Click here to Skip to main content
15,886,518 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 33K   1.4K   22  
A .NET control to control the layout of categorized sections in your application.
Public Class Form1
    Dim TestPanel As YSSPAutoFlowButtonsPanel.YSSPAutoFlowButtonsPanel
    Dim LeftPanel As YSSPAutoFlowButtonsPanel.YSSPAutoFlowButtonsPanel
    Dim ButtonsTextAlign As ContentAlignment = ContentAlignment.MiddleCenter

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        TestPanel = New YSSPAutoFlowButtonsPanel.YSSPAutoFlowButtonsPanel(Me)
        TestPanel.Name = "TestPanel"
        TestPanel.Height = Me.Height
        TestPanel.Width = 350
        TestPanel.Top = 7
        TestPanel.Left = 520
        TestPanel.BorderStyle = BorderStyle.FixedSingle
        TestPanel.PanelsSettings.BackColor = Color.Aqua
        ' TestPanel.Dock = DockStyle.Right
        ' TestPanel.Anchor = AnchorStyles.Bottom And AnchorStyles.Top
        Dim B As YSSPAutoFlowButtonsPanel.YSSPButton
        For I As Integer = 0 To 100
            B = New YSSPAutoFlowButtonsPanel.YSSPButton()
            B.Name = "BTN" & I
            B.Text = "Button " & I
            TestPanel.Buttons.Add(B)
        Next


        LeftPanel = New YSSPAutoFlowButtonsPanel.YSSPAutoFlowButtonsPanel(Me)
        LeftPanel.Name = "LeftPanel"
        LeftPanel.Height = Me.Height - 10
        LeftPanel.Width = 520
        LeftPanel.Top = 7
        LeftPanel.Left = 10
        LeftPanel.Dock = DockStyle.Left
        LeftPanel.ButtonsSettings.width = 490
        LeftPanel.ButtonsSettings.Left = 5
        LeftPanel.ButtonsSettings.Height = 50
        LeftPanel.BorderStyle = BorderStyle.FixedSingle
        LeftPanel.PanelsSettings.BackColor = Color.Aqua

        'add a penel that contains test commands for AutoFlowLayoutPanel settings 
        B = New YSSPAutoFlowButtonsPanel.YSSPButton()
        B.Name = "BTN1"
        B.Text = "AutoFlowLayoutPanel"
        B.InnerPanel.Width = 463
        B.InnerPanel.Height = 325
        B.InnerPanel.Controls.Add(TestAFLPanel)
        LeftPanel.Buttons.Add(B)

        'add a penel that contains test commands for AutoFlowLayoutPanel buttons' settings 
        B = New YSSPAutoFlowButtonsPanel.YSSPButton()
        B.Name = "BTN2"
        B.Text = "Buttons"
        B.InnerPanel.Width = 463
        B.InnerPanel.Height = 518
        B.InnerPanel.Controls.Add(TestButtonsPanel)
        LeftPanel.Buttons.Add(B)

        'add a penel that contains test commands for inner panels settings 
        B = New YSSPAutoFlowButtonsPanel.YSSPButton()
        B.Name = "BTN3"
        B.Text = "Inner Panels"
        B.InnerPanel.Width = 463
        B.InnerPanel.Height = 518
        B.InnerPanel.Controls.Add(TestInnerPanelsPanel)
        LeftPanel.Buttons.Add(B)

        'add a penel that contains test commands for this test application 
        B = New YSSPAutoFlowButtonsPanel.YSSPButton()
        B.Name = "BTN4"
        B.Text = "Test Application"
        B.InnerPanel.Width = 463
        B.InnerPanel.Height = 127
        B.InnerPanel.Controls.Add(TestApplicationPanel)
        LeftPanel.Buttons.Add(B)



    End Sub

    ' Panel Settings test commands
    Private Sub PS_ShiftLayoutView_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PS_ShiftLayoutView.Click
        If TestPanel.Settings.LayoutVeiw = YSSPAutoFlowButtonsPanel.LayoutVeiw.MultiVewi Then
            TestPanel.Settings.LayoutVeiw = YSSPAutoFlowButtonsPanel.LayoutVeiw.SingleVeiw
        Else
            TestPanel.Settings.LayoutVeiw = YSSPAutoFlowButtonsPanel.LayoutVeiw.MultiVewi
        End If
    End Sub
    Private Sub PS_ShiftButtonsStyle_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PS_ShiftButtonsStyle.Click
        If TestPanel.Settings.ButtonsStyle = YSSPAutoFlowButtonsPanel.ButtonsStyle.Graphical Then
            TestPanel.Settings.ButtonsStyle = YSSPAutoFlowButtonsPanel.ButtonsStyle.System
        Else
            TestPanel.Settings.ButtonsStyle = YSSPAutoFlowButtonsPanel.ButtonsStyle.Graphical
        End If
    End Sub

    Private Sub PS_Backcolor_Apply_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PS_Backcolor_Apply.Click
        TestPanel.BackColor = PS_Backcolor_Pic.BackColor
    End Sub
    Private Sub PS_Backcolor_Pic_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PS_Backcolor_Pic.Click
        PS_Backcolor_Pic.BackColor = GetColor()
    End Sub

    Private Sub PS_Width_Apply_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PS_Width_Apply.Click
        If PS_Width_TXT.Text <> "" Then
            If IsNumeric(PS_Width_TXT.Text) Then _
            TestPanel.Width = PS_Width_TXT.Text
        End If
    End Sub
    Private Sub PS_Height_Aplly_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PS_Height_Aplly.Click
        If PS_Height_TXT.Text <> "" Then
            If IsNumeric(PS_Height_TXT.Text) Then _
            TestPanel.Height = PS_Height_TXT.Text
        End If
    End Sub
    Private Sub PS_Left_Aplly_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PS_Left_Aplly.Click
        If PS_Left_TXT.Text <> "" Then
            If IsNumeric(PS_Left_TXT.Text) Then _
            TestPanel.Settings.Left = PS_Left_TXT.Text
        End If
    End Sub
    Private Sub PS_Top_Aplly_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PS_Top_Aplly.Click
        If PS_Top_TXT.Text <> "" Then
            If IsNumeric(PS_Top_TXT.Text) Then _
            TestPanel.Top = PS_Top_TXT.Text
        End If
    End Sub
    Private Sub PS_RTL_Aplly_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PS_RTL_Aplly.Click
        If PS_RTL_ComboBox.SelectedIndex < 0 Then Return
        TestPanel.RightToLeft = PS_RTL_ComboBox.SelectedIndex
    End Sub


    ' Panel's buttons Settings test commands
    Private Sub BS_Forecolor_Pic_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BS_Forecolor_Pic.Click
        BS_Forecolor_Pic.BackColor = GetColor()
    End Sub
    Private Sub BS_Forecolor_Apply_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BS_Forecolor_Apply.Click
        TestPanel.ButtonsSettings.ForeColor = BS_Forecolor_Pic.BackColor
    End Sub

    Private Sub BS_Backcolor_Pic_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BS_Backcolor_Pic.Click
        BS_Backcolor_Pic.BackColor = GetColor()
    End Sub
    Private Sub BS_Backcolor_Apply_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BS_Backcolor_Apply.Click
        TestPanel.ButtonsSettings.BackColor = BS_Backcolor_Pic.BackColor
    End Sub

    
    Private Sub BS_Width_Apply_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BS_Width_Apply.Click
        If BS_Width_TXT.Text <> "" Then
            If IsNumeric(BS_Width_TXT.Text) Then _
            TestPanel.ButtonsSettings.width = BS_Width_TXT.Text
        End If
    End Sub
    Private Sub BS_Height_Apply_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BS_Height_Apply.Click
        If BS_Height_TXT.Text <> "" Then
            If IsNumeric(BS_Height_TXT.Text) Then _
            TestPanel.ButtonsSettings.Height = BS_Height_TXT.Text
            TestPanel.ReArrange() ' must be calles after changing buttons and panels' height to get them work correctly (or the will be re-arranged after user clicks on any button) 

        End If
    End Sub
    Private Sub BS_Left_Apply_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BS_Left_Apply.Click
        If BS_Left_TXT.Text <> "" Then
            If IsNumeric(BS_Left_TXT.Text) Then _
            TestPanel.ButtonsSettings.Left = BS_Left_TXT.Text
        End If
    End Sub

    Private Sub BS_RTL_Apply_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BS_RTL_Apply.Click
        If BS_RTL_ComboBox.SelectedIndex < 0 Then Return
        TestPanel.ButtonsSettings.RightToLeft = BS_RTL_ComboBox.SelectedIndex
    End Sub

    Private Sub BS_TextAlign_TL_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BS_TextAlign_TL.Click
        'change local variable value to holdthe text align of the panel's buttons
        ButtonsTextAlign = ContentAlignment.TopLeft
    End Sub
    Private Sub BS_TextAlign_TC_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BS_TextAlign_TC.Click
        'change local variable value to holdthe text align of the panel's buttons
        ButtonsTextAlign = ContentAlignment.TopCenter
    End Sub
    Private Sub BS_TextAlign_TR_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BS_TextAlign_TR.Click
        'change local variable value to holdthe text align of the panel's buttons
        ButtonsTextAlign = ContentAlignment.TopRight
    End Sub

    Private Sub BS_TextAlign_ML_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BS_TextAlign_ML.Click
        'change local variable value to holdthe text align of the panel's buttons
        ButtonsTextAlign = ContentAlignment.MiddleLeft
    End Sub
    Private Sub BS_TextAlign_MC_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BS_TextAlign_MC.Click
        'change local variable value to holdthe text align of the panel's buttons
        ButtonsTextAlign = ContentAlignment.MiddleCenter
    End Sub
    Private Sub BS_TextAlign_MR_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BS_TextAlign_MR.Click
        'change local variable value to holdthe text align of the panel's buttons
        ButtonsTextAlign = ContentAlignment.MiddleRight
    End Sub

    Private Sub BS_TextAlign_BL_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BS_TextAlign_BL.Click
        'change local variable value to holdthe text align of the panel's buttons
        ButtonsTextAlign = ContentAlignment.BottomLeft
    End Sub
    Private Sub BS_TextAlign_BC_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BS_TextAlign_BC.Click
        'change local variable value to holdthe text align of the panel's buttons
        ButtonsTextAlign = ContentAlignment.BottomCenter
    End Sub
    Private Sub BS_TextAlign_BR_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BS_TextAlign_BR.Click
        'change local variable value to holdthe text align of the panel's buttons
        ButtonsTextAlign = ContentAlignment.BottomRight
    End Sub

    Private Sub BS_TextAlign_Apply_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BS_TextAlign_Apply.Click
        TestPanel.ButtonsSettings.TextAlign = ButtonsTextAlign
    End Sub

    Private Sub BS_MainImage_Browse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BS_MainImage_Browse.Click
        BS_MainImage_Pic.BackgroundImage = GetImage(BS_MainImage_TXT)
    End Sub
    Private Sub BS_MainImage_Pic_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BS_MainImage_Pic.Click
        BS_MainImage_Browse_Click(sender, e)
    End Sub
    Private Sub BS_MainImage_Apply_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BS_MainImage_Apply.Click
        TestPanel.ButtonsSettings.MainImage = BS_MainImage_Pic.BackgroundImage
    End Sub

    Private Sub BS_OverImage_Browse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BS_OverImage_Browse.Click
        BS_OverImage_Pic.BackgroundImage = GetImage(BS_OverImage_TXT)
    End Sub
    Private Sub BS_OverImage_Pic_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BS_OverImage_Pic.Click
        BS_OverImage_Browse_Click(sender, e)
    End Sub
    Private Sub BS_OverImage_Apply_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BS_OverImage_Apply.Click
        TestPanel.ButtonsSettings.OverImage = BS_OverImage_Pic.BackgroundImage
    End Sub

    Private Sub BS_DownImage_Browse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BS_DownImage_Browse.Click
        BS_DownImage_Pic.BackgroundImage = GetImage(BS_DownImage_TXT)
    End Sub
    Private Sub BS_DownImage_Pic_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BS_DownImage_Pic.Click
        BS_DownImage_Browse_Click(sender, e)
    End Sub
    Private Sub BS_DownImage_Apply_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BS_DownImage_Apply.Click
        TestPanel.ButtonsSettings.DownImage = BS_DownImage_Pic.BackgroundImage
    End Sub

    Private Sub BS_SelectedImage_Browse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BS_SelectedImage_Browse.Click
        BS_SelectedImage_Pic.BackgroundImage = GetImage(BS_SelectedImage_TXT)
    End Sub
    Private Sub BS_SelectedImage_Pic_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BS_SelectedImage_Pic.Click
        BS_SelectedImage_Browse_Click(sender, e)
    End Sub
    Private Sub BS_SelectedImage_Apply_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BS_SelectedImage_Apply.Click
        TestPanel.ButtonsSettings.SelectedImage = BS_SelectedImage_Pic.BackgroundImage
    End Sub


    ' Panel's inner panels Settings test commands
    Private Sub INP_BackgroundImage_Browse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles INP_BackgroundImage_Browse.Click
        INP_BackgroundImage_PIC.BackgroundImage = GetImage(INP_BackgroundImage_TXT)
    End Sub
    Private Sub INP_BackgroundImage_PIC_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles INP_BackgroundImage_PIC.Click
        INP_BackgroundImage_Browse_Click(sender, e)
    End Sub
    Private Sub INP_BackgroundImage_Apply_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles INP_BackgroundImage_Apply.Click
        TestPanel.PanelsSettings.BackgroundImage = INP_BackgroundImage_PIC.BackgroundImage
    End Sub

    Private Sub INP_BackgroundImageLayout_Apply_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles INP_BackgroundImageLayout_Apply.Click
        If INP_BackgroundImageLayout_ComboBox.SelectedIndex < 0 Then Return
        TestPanel.PanelsSettings.BackgroundImageLayout = INP_BackgroundImageLayout_ComboBox.SelectedIndex
    End Sub

    Private Sub INP_Forecolor_Pic_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles INP_Forecolor_Pic.Click
        INP_Forecolor_Pic.BackColor = GetColor()
    End Sub
    Private Sub INP_Forecolor_Apply_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles INP_Forecolor_Apply.Click
        TestPanel.PanelsSettings.ForeColor = INP_Forecolor_Pic.BackColor
    End Sub

    Private Sub INP_Backcolor_Pic_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles INP_Backcolor_Pic.Click
        INP_Backcolor_Pic.BackColor = GetColor()
    End Sub
    Private Sub INP_Backcolor_Apply_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles INP_Backcolor_Apply.Click
        TestPanel.PanelsSettings.BackColor = INP_Backcolor_Pic.BackColor
    End Sub

    Private Sub INP_Width_Apply_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles INP_Width_Apply.Click
        If INP_Width_TXT.Text <> "" Then
            If IsNumeric(INP_Width_TXT.Text) Then _
            TestPanel.PanelsSettings.width = INP_Width_TXT.Text
        End If
    End Sub
    Private Sub INP_Height_Apply_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles INP_Height_Apply.Click
        If INP_Height_TXT.Text <> "" Then
            If IsNumeric(INP_Height_TXT.Text) Then _
            TestPanel.PanelsSettings.Height = INP_Height_TXT.Text
            TestPanel.ReArrange() ' must be calles after changing buttons and panels' height to get them work correctly (or the will be re-arranged after user clicks on any button) 
        End If
    End Sub
    Private Sub INP_Left_Apply_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles INP_Left_Apply.Click
        If INP_Left_TXT.Text <> "" Then
            If IsNumeric(INP_Left_TXT.Text) Then _
            TestPanel.PanelsSettings.Left = INP_Left_TXT.Text
        End If
    End Sub

    Private Sub INP_RTL_Apply_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles INP_RTL_Apply.Click
        If INP_RTL_ComboBox.SelectedIndex < 0 Then Return
        TestPanel.PanelsSettings.RightToLeft = INP_RTL_ComboBox.SelectedIndex
    End Sub

    ' test application
    Private Sub Exit_BTN_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Exit_BTN.Click
        End
    End Sub

    ' shared functions
    Private Function GetColor() As Color
        ColorDialog1.ShowDialog()
        Return ColorDialog1.Color
    End Function
    Private Function GetImage(ByVal TextBox As TextBox) As Image
        OpenFileDialog1.CheckFileExists = True
        OpenFileDialog1.CheckPathExists = True
        OpenFileDialog1.Filter = "JPG Images (*.jpeg) |*.jpg| PNG Images (*.png) |*.png| BMP Images (*.bmp)|*.bmp| All Files | *.*"
        OpenFileDialog1.ShowDialog()

        Try
            Dim img As Image = Image.FromFile(OpenFileDialog1.FileName)
            TextBox.Text = OpenFileDialog1.FileName
            Return img
        Catch ex As Exception
            TextBox.Text = ""
            Return Nothing
        End Try


    End Function
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