Reputation: 880
I am using the following code to create text boxes at run time and it's working perfectly:
MarginTextbox.Name = "mid" & id
MarginLabel.Name = "ML" & id
MarginTextbox.Font = New System.Drawing.Font("Verdana", 10, Drawing.FontStyle.Regular)
MarginLabel.Location = New Point(15, (80 + (counter * 24)))
MarginTextbox.Location = New Point(110, (80 + (counter * 24)))
MarginLabel.BackColor = Me.BackColor
MarginTextbox.Size = New Size(56, 20)
MarginLabel.Size = New Size(150, 20)
MarginTextbox.AutoSize = False
MarginLabel.Text = "Supplier " & id
Controls.Add(MarginTextbox)
Controls.Add(MarginLabel)
I don't want to place them on the form, but rather in a TabControl tab. How can I do that?
Upvotes: 0
Views: 3974
Reputation: 216311
A TabControl contains one or more TabPage.
The TabPage has a Controls object collection that can be used to add your textboxes.
So (supposing you have added a TabControl named tabControl1):
Dim tp as TabPage = tabControl1.TabPages(0) ' 0 is the index of the page required'
tp.Controls.Add(MarginTextbox)
tp.Controls.Add(MarginLabel)
Upvotes: 3
Reputation: 225054
Instead of adding the controls to your Form
's Controls
, add it to your TabPage
's Controls
:
Controls.Add(MarginTextbox)
Controls.Add(MarginLabel)
Me.TabPageWhatever.Controls.Add(MarginTextbox)
Me.TabPageWhatever.Controls.Add(MarginLabel)
Upvotes: 1