title: Create Winform controls dynamically - VB.NET
body: <p>I want to create a simple <strong>Winform</strong> application that contains multiple blocks . </p>
  
  <p>Each block is a <strong>FlowLayoutPanel</strong> container that holds the following form controls: <em>(Image attached for reference)</em></p>
  
  <ol>
  <li><strong>Label</strong></li>
  <li><strong>TextBox</strong></li>
  <li><strong>ListBox</strong></li>
  <li><strong>CheckBox</strong></li>
  </ol>
  
  <p><a href="https://i.stack.imgur.com/Gj1s1.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Gj1s1.png" alt="Sample UI"></a></p>
  
  <p><strong>Sample Code</strong></p>
  
  <pre><code>&lt;Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()&gt; _
  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.
  &lt;System.Diagnostics.DebuggerNonUserCode()&gt; _
  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.
  
  
  '&lt;System.Diagnostics.DebuggerStepThrough()&gt;
  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
  </code></pre>
  
  <p>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 <strong>for/while</strong> loop to achieve this.</p>