Question

its my first time using tabs and I've ran into a problem. I'm trying to make it so whenever I press a button, combo boxes will appear inside the tab that is open, and then if the button is pressed again it will add another combo box underneath the first one.

Here is how I did it:

private void buttonLevel4Add_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < 8; i++)
            {

                comboBoxModuleSelect.Add(new ComboBox());
                System.Drawing.Point p = new System.Drawing.Point(176, 114 + i * 25);
                (comboBoxModuleSelect[i] as ComboBox).Location = p;
                (comboBoxModuleSelect[i] as ComboBox).Size = new     System.Drawing.Size(183, 20);

                this.Controls.Add(comboBoxModuleSelect[i] as ComboBox);
            }
        }

But the problem is that the combo box won't be created in the tab page but underneath the tab page (i.e. on the form). Does a tab page not replace the form area? Please if someone could help I would appreciate it. Thanks

EDIT:

Oh God, another noob moment for me. I changed this line:

this.Controls.Add(comboBoxModuleSelect[i] as ComboBox);

to:

tabpage.Controls.Add(comboBoxModuleSelect[i] as ComboBox);

really sorry, I guess it just helps me to ask the question and think about it.

Was it helpful?

Solution

this.Controls.Add(comboBoxModuleSelect[i] as ComboBox);

to:

tabpage.Controls.Add(comboBoxModuleSelect[i] as ComboBox);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top