Hello, I'm fairly new to VB.NET
I'm trying to add a textbox to a tabpage, which neither exist at design/compile time. The TabControl1 already exists, but the textboxes and tabpages don't. Here is my code so far (without any way to add the textboxes).

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim txtBoxNew As New TextBox
        Dim tabPageNew As New TabPage

        Me.TabControl1.TabPages.Add(tabPageNew)
        'add txtBoxNew to tabPageNew..

    End Sub

I declare a variable to the new textbox, but I don't know how to place it in tabPageNew.

Any pointers? Thanks,
-Dave

Recommended Answers

All 3 Replies

Hi,

Check this:

Dim NewTab As New TabPage
        Dim NewTextBox As New TextBox

        Me.TabControl1.Controls.Add(NewTab)
        NewTab.Controls.Add(NewTextBox)

Thank you for that. Precisely what I was looking for.

Is there a difference between:

tabControl.TabPages.Add(NewTab)

and

tabControl.Controls.Add(NewTab)

?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.