title: Programmatically add controls to form
body: <p>I'm using the attached code to add another line\row of controls beneath an existing set (when a label is clicked). There could be quite a few rows added so I'm having to repeat the code many times using the counter (i) to keep track...</p>
  
  <p>Is there a better method for doing this?</p>
  
  <pre><code>Private Sub Label10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)      Handles LblExpandSearch.Click
      If i = 0 Then
  
          'TextBox7
          '
          Dim TextBox7 As New TextBox
          TextBox7.Size = New Size(302, 20)
          TextBox7.Name = "TextBox7"
          TextBox7.Location = New System.Drawing.Point(60, 135)
          Me.ExpAdvancedSearch.Controls.Add(TextBox7)
  
          'RadioButton5
          '
          Dim RadioButton5 As New RadioButton
          RadioButton5.AutoSize = True
          RadioButton5.Checked = True
          RadioButton5.Location = New System.Drawing.Point(77, 112)
          RadioButton5.Name = "RadioButton5"
          RadioButton5.Size = New System.Drawing.Size(55, 17)
          RadioButton5.TabIndex = 48
          RadioButton5.TabStop = True
          RadioButton5.Text = "NEAR"
          RadioButton5.UseVisualStyleBackColor = True
  
      ElseIf i = 1 Then
  
          ExpAdvancedSearch.Size_ExpandedHeight = 260
  
          'TextBox8
          '
          Dim TextBox8 As New TextBox
          TextBox8.Size = New Size(302, 20)
          TextBox8.Name = "TextBox8"
          TextBox8.Location = New System.Drawing.Point(60, 185)
          Me.ExpAdvancedSearch.Controls.Add(TextBox8)
  
  
          'RadioButton9
          '
          Dim RadioButton9 As New RadioButton
          RadioButton9.AutoSize = True
          RadioButton9.Checked = True
          RadioButton9.Location = New System.Drawing.Point(77, 162)
          RadioButton9.Name = "RadioButton9"
          RadioButton9.Size = New System.Drawing.Size(55, 17)
          RadioButton9.TabIndex = 48
          RadioButton9.TabStop = True
          RadioButton9.Text = "NEAR"
          RadioButton9.UseVisualStyleBackColor = True
  
      End If
  
      i = i + 1
  End Sub
  </code></pre>