I want to create a simple Winform application that contains multiple blocks .
Each block is a FlowLayoutPanel container that holds the following form controls: (Image attached for reference)
- Label
- TextBox
- ListBox
- CheckBox
Sample Code
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class NXOpenWinForm
Inherits System.Windows.Forms.Form
Public Sub New()
InitializeComponent()
NXOpenUI.FormUtilities.SetApplicationIcon(Me)
NXOpenUI.FormUtilities.ReparentForm(Me)
End Sub
'Form overrides dispose to clean up the component list.
<System.Diagnostics.DebuggerNonUserCode()> _
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
Try
If disposing AndAlso components IsNot Nothing Then
components.Dispose()
End If
Finally
MyBase.Dispose(disposing)
End Try
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
'<System.Diagnostics.DebuggerStepThrough()>
Private Sub InitializeComponent()
Me.FlowLayoutPanel1 = New System.Windows.Forms.FlowLayoutPanel()
Me.Label1 = New System.Windows.Forms.Label()
Me.TextBox1 = New System.Windows.Forms.TextBox()
Me.ListBox1 = New System.Windows.Forms.ListBox()
Me.CheckBox1 = New System.Windows.Forms.CheckBox()
Me.FlowLayoutPanel1.SuspendLayout()
Me.SuspendLayout()
'
'FlowLayoutPanel1
'
Me.FlowLayoutPanel1.Controls.Add(Me.Label1)
Me.FlowLayoutPanel1.Controls.Add(Me.TextBox1)
Me.FlowLayoutPanel1.Controls.Add(Me.ListBox1)
Me.FlowLayoutPanel1.Controls.Add(Me.CheckBox1)
Me.FlowLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Top
Me.FlowLayoutPanel1.Location = New System.Drawing.Point(0, 0)
Me.FlowLayoutPanel1.Name = "FlowLayoutPanel1"
Me.FlowLayoutPanel1.Padding = New System.Windows.Forms.Padding(2)
Me.FlowLayoutPanel1.Size = New System.Drawing.Size(641, 105)
Me.FlowLayoutPanel1.TabIndex = 0
'
'Label1
'
Me.Label1.Anchor = System.Windows.Forms.AnchorStyles.Left
Me.Label1.AutoSize = True
Me.Label1.Location = New System.Drawing.Point(5, 46)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(39, 13)
Me.Label1.TabIndex = 0
Me.Label1.Text = "Label1"
'
'TextBox1
'
Me.TextBox1.Anchor = System.Windows.Forms.AnchorStyles.Left
Me.TextBox1.Location = New System.Drawing.Point(50, 5)
Me.TextBox1.Multiline = True
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.Size = New System.Drawing.Size(169, 94)
Me.TextBox1.TabIndex = 1
'
'ListBox1
'
Me.ListBox1.Anchor = System.Windows.Forms.AnchorStyles.Left
Me.ListBox1.FormattingEnabled = True
Me.ListBox1.Location = New System.Drawing.Point(225, 5)
Me.ListBox1.Name = "ListBox1"
Me.ListBox1.Size = New System.Drawing.Size(291, 95)
Me.ListBox1.TabIndex = 2
'
'CheckBox1
'
Me.CheckBox1.Anchor = System.Windows.Forms.AnchorStyles.Left
Me.CheckBox1.AutoSize = True
Me.CheckBox1.Location = New System.Drawing.Point(522, 44)
Me.CheckBox1.Name = "CheckBox1"
Me.CheckBox1.Size = New System.Drawing.Size(81, 17)
Me.CheckBox1.TabIndex = 3
Me.CheckBox1.Text = "CheckBox1"
Me.CheckBox1.UseVisualStyleBackColor = True
'
'NXOpenWinForm
'
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.ClientSize = New System.Drawing.Size(641, 351)
Me.Controls.Add(Me.FlowLayoutPanel1)
Me.Name = "NXOpenWinForm"
Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent
Me.Text = "Test App"
Me.FlowLayoutPanel1.ResumeLayout(False)
Me.FlowLayoutPanel1.PerformLayout()
Me.ResumeLayout(False)
End Sub
Friend WithEvents FlowLayoutPanel1 As Windows.Forms.FlowLayoutPanel
Friend WithEvents Label1 As Windows.Forms.Label
Friend WithEvents TextBox1 As Windows.Forms.TextBox
Friend WithEvents ListBox1 As Windows.Forms.ListBox
Friend WithEvents CheckBox1 As Windows.Forms.CheckBox
End Class
In the image above, I have created a block manually. I wish to generate n-number of such blocks. Is it possible to generate these blocks dynamically during run-time? Not sure if I can use a simple for/while loop to achieve this.

Controlscollection. Depending on your use case it might be preferable to use a repeating or list control and make use of its Template instead if your composite control is data-bound. - FilburtInitializeComponent()- register an EventHandler for theOnLoadevent and put your loop there. However I'd still suggest to use a databound control ... even if you just bind a list of names to put into your Label. - FilburtDataGridView. Also you can consider using aDataRepeatercontrol. If the pattern for each row is the same, you can useUserControl. Also take a look at this post. - Reza Aghaei