0
private void referenceDesk_DoubleClick(object sender, EventArgs e)
{
    tabControl1.TabPages.Add(new TabPage("Donkey Kong"));
}

there is no tabControl1.Modifier type command to use, and also can't use

new public TabPage("");
Mohammad Dehghan
  • 17,853
  • 3
  • 55
  • 72
yumyum
  • 7
  • 6
  • What do you want to achieve? – abatishchev Feb 10 '13 at 05:00
  • tabControl1 is already set to public i'd like any page added tControl1.TabPages[index] to be also set to public – yumyum Feb 10 '13 at 05:02
  • Is tabControl1 created with form designer and you want to change its modifier? – abatishchev Feb 10 '13 at 05:04
  • no, it is created from designer, and it is already set to have a public modifier. New TabPages are added to that and the default is private as on all other Controls. How do you change the setting on the runtime-added TabPages? – yumyum Feb 10 '13 at 05:07
  • [No there's no such a thing to modify the modifiers](http://stackoverflow.com/questions/3111652/why-theres-no-modifiers-public-private-protected-in-front-of-methods-and-pr) – spajce Feb 10 '13 at 05:28

2 Answers2

1

The Modifiers design-time property, controls member creation for the object you are modifying. It is not something you can change later. If you want to add tab pages to a tab control and you want to be able to change them later, define class members for them and assign appropriate access-modifier to them:

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }

    private List<TabPage> tabPages;

    private void referenceDesk_DoubleClick(object sender, EventArgs e)
    {
        tabPages = new List<TabPage>();
        tabPages.Add(new TabPage("First"));
        tabPages.Add(new TabPage("Second"));
        foreach (var tab in tabPages)
            tabControl1.TabPages.Add(tab);
    }

    ....
}
Mohammad Dehghan
  • 17,853
  • 3
  • 55
  • 72
  • Has to be done in a List format? Is this even possible? – yumyum Feb 10 '13 at 05:11
  • possibly has to utilize the dynamic keyword? It's an indefinite amount of pages.. so they need to be created at runtime. @MD.Unicorn the private List tabPages will apply private to each of the pages? – yumyum Feb 10 '13 at 05:22
  • It is dynamic. You can add any number of pages to the list and to the tab control. Access-modifiers control access to the **class members** from **outside of the class**. Now the class member is `tabPages` itself. You need to read some books about object-oriented programming and C#. – Mohammad Dehghan Feb 10 '13 at 05:28
0

Designer code is not supposed to be user modified, as it gets re-written by Visual Studio every time you make changes to your form in the designer (as you have discovered).

One way forward it to move the control declaration and initialization to the non designer code file. However, that means your control will no longer appear in the designer.

  • off topic. There are controls added to it, which need the public modifier to be set, how do you achieve this on the new TabPages that get added? – yumyum Feb 10 '13 at 05:06