I have a couple of questions about tab controls.

1. How do you access the specific tabs and edit their properties? For example if I want to change the name of tabPage1 to "blank".

2. How do you create a new tab page with code? So if I press button1 it creates a new tab?


In addition to 1, there are several other controls that have a similar layout of having to open a new dialogue box to add things (such as list items in a list box). Do you interact with these the same way?

Recommended Answers

All 2 Replies

Heres all you need:

private void button1_Click(object sender, EventArgs e)
        {
            //changing name and text property of the tabPage1 (of the tabContgrol1):
            tabPage1.Name = String.Empty;
            tabPage1.Text = "LOOK";

            //creating new tabPage (of th tabControl1):
            int countPages = tabControl1.TabPages.Count;
            TabPage newPage = new TabPage();
            newPage.Name = "tabPage" + countPages;
            newPage.Text = "LOOK - NEW TABPAGE";
            tabControl1.TabPages.Add(newPage);
        }

about your last question, answer is Yes.
YOu can edit their properties in the code (in runtime) without any problem. Just be careful, that changes wont influence to the rest of th code (jusr be careful, ok?).
bye
Mitja

Thanks, great code. Solved.

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.