Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 926193
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T19:38:43+00:00 2026-05-15T19:38:43+00:00

I’m using the attached code to add another line\row of controls beneath an existing

  • 0

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…

Is there a better method for doing this?

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
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T19:38:44+00:00Added an answer on May 15, 2026 at 7:38 pm

    Hmmm.. UseVisualStyleBackColor says ‘winforms’ to me.

    A few points…

    Don’t add controls all to one panel, use a usercontrol.

    Then just add instances of that.

    Don’t process click events from a label

    Use a linklabel or button. Anything else = being mean to users. Of course it makes sense to you, you thought of it! Now so with users, this is black and white.

    Sample…

    Very minimal of course. You’ll want to:

    • Put the items in a scrollable panel instead of right on the form.
    • Add them to a generic list of uc probably, too.
    • Set form’s min/max size – to allow reasonable sizing (allow any height > ~100)
    • Set uc’s and controls .Anchor properties to allow reasonable resizing

    uc.vb

    Public Class uc
        Inherits System.Windows.Forms.UserControl
    
        Private components As System.ComponentModel.IContainer
        Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
        Friend WithEvents LinkLabel1 As System.Windows.Forms.LinkLabel
    
        Public Sub New()
            MyBase.New()
    
            Me.TextBox1 = New System.Windows.Forms.TextBox
            Me.LinkLabel1 = New System.Windows.Forms.LinkLabel
            Me.SuspendLayout()
    
            Me.TextBox1.Location = New System.Drawing.Point(8, 8)
            Me.TextBox1.Name = "TextBox1"
            Me.TextBox1.Size = New System.Drawing.Size(88, 20)
            Me.TextBox1.TabIndex = 0
            Me.TextBox1.Text = "TextBox1"
    
            Me.LinkLabel1.Enabled = False
            Me.LinkLabel1.Location = New System.Drawing.Point(112, 8)
            Me.LinkLabel1.Name = "LinkLabel1"
            Me.LinkLabel1.Size = New System.Drawing.Size(24, 16)
            Me.LinkLabel1.TabIndex = 1
            Me.LinkLabel1.TabStop = True
            Me.LinkLabel1.Text = "add"
    
            Me.Controls.Add(Me.LinkLabel1)
            Me.Controls.Add(Me.TextBox1)
            Me.Name = "uc"
            Me.Size = New System.Drawing.Size(148, 36)
            Me.ResumeLayout(False)
    
        End Sub
    
        Private _addcallback As EventHandler = Nothing
        Public Property AddCallback() As EventHandler
            Get
                Return _addcallback
            End Get
            Set(ByVal Value As EventHandler)
    
                _addcallback = Value
                LinkLabel1.Enabled = Not Value Is Nothing
    
            End Set
        End Property
    
        Private Sub LinkLabel1_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles LinkLabel1.LinkClicked
            If AddCallback Is Nothing Then Throw New ApplicationException("AddCallback not set on a uc") ' ALWAYS check for errors like this 
            _addcallback(Me, Nothing)
            AddCallback = Nothing ' gray myself out, can't insert in thie implementation
        End Sub
    End Class
    

    frm.vb

    Public Class frm
        Inherits System.Windows.Forms.Form
    
        Private components As System.ComponentModel.IContainer
        Public Sub New()
            MyBase.New()
            Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
            Me.ClientSize = New System.Drawing.Size(292, 266)
            Me.Name = "Form1"
            Me.Text = "Form1"
        End Sub
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            AddClicked(Me, Nothing)
        End Sub
    
        Private Sub AddClicked(ByVal sender As Object, ByVal e As System.EventArgs)
            Dim myuc As New uc
            myuc.AddCallback = AddressOf AddClicked
            If Controls.Count > 0 Then
                myuc.Top = Controls(Controls.Count - 1).Bottom
            End If
            Me.Controls.Add(myuc)
        End Sub
    End Class
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.