work with FlowLayoutPanel in ASP.NET Using VB.NET
In this article we demonstrate on what is FlowLayoutPanel.its properties and how you can work with FlowLayoutPanel control.
A visual basic FlowLayoutPanel control represents a Panel that dynamically lays out its contents horizontally or vertically. The FlowLayoutPanel is derived from Panel control. It is most commonly used to create container for group of similar controls. The FlowLayoutPanel dynamically repositions the control it contains. In FlowLayoutPanel, whatever control that you place in the panel will rearrange itself to right of the previous control, in a flowing model. If the right side of the previous control does not have enough space. It would wrap itself to the next available space at the bottom. you accomplish this by setting Anchor property of the FlowLayouPanel as we set it in the article(Top,Bottom,Left.Right). The FlowLayoutPanel also supports a scroll. The scroll will only work when its AutoScroll property set to true. You will also set the WrapContent property of the FlowLayoutPanel. If the WrapContent property of the FlowLayoutPanel is set to false it will stop wrapping the contents and go on adding the controls on the same row or column.
Properties of FlowLayoutPanel control:-
- AutoScrollPosition:- This property gets/sets the location of Auto-scroll position.
- BorderStyle:- Indicate the BorderStyle of the Control.
- BackColor:- This property gets/sets the background color of the control.
- BindingContext:- This property gets/sets the BindingContext for the control.
How FlowLayoutPanel control work:-
- Simply just open a new project
- Drag a FlowLayoutPanel control on form, sets it AutoScroll property to true, anchor to Top, Bottom, Left, Right and WrapContent to true. The form will look like below.
- If you will resize the form the form will something look like below.
- Write the below code.
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Adding 10 TextBoxes to the FlowLayout Panel
For index As Integer = 0 To 11
Dim txt As New TextBox()
txt.Name = "Txt " & (index + 1)
txt.Text = txt.Name
If index Mod 2 Then
FlowLayoutPanel1.SetFlowBreak(txt, True) 'Setting the FlowBreak at every Even index