Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27201

Add new tab (containing objects) with a click

$
0
0
Hi all

I want to, with a click of a button add a new tab that contains a preset amount of objects - 2 Labels, 2 buttons ("Add" and "X"). The "Add" button will insert a checkbox and a textbox next to it.

The attached file will bring clarity to my explanation.

Name:  Capture.JPG
Views: 39
Size:  40.0 KB

The code that I have is as follows:

Code:

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim newTab As New TabPage
        TabControl1.Controls.Add(newTab)
        newTab.Text = ComboBox1.Text
        Call tabContents()
        ComboBox1.Text = ""
        ContractBox.Text = ""

    End Sub

    Public Sub tabContents()
        Dim newLabel As New Label
        Dim newLabel2 As New Label

        TabControl1.Controls.Add(newLabel)
        With newLabel
            .Text = ComboBox1.Text
            .Location = New Point(6, 20)
        End With

        TabControl1.Controls.Add(newLabel2)
        With newLabel2
            .Text = ContractBox.Text
            .Location = New Point(306, 20)
        End With
    End Sub

First of all, when I click the big grey Add button, Visual Studio gives the following error:

Quote:

An unhandled exception of type 'System.ArgumentException' occurred in System.Windows.Forms.dll
Additional information: Cannot add 'Label' to TabControl. Only TabPages can be directly added to TabControls.
Let's first stop here for now.

Thanks in advance for your help!!
Attached Images
 

Viewing all articles
Browse latest Browse all 27201

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>