Question

How to set Key for a tabpage

I have a tabcontrol1 in which i am adding a tabpage programatically.

TabPage tabpagep1=new TabPage("");
tabpagep1.Name = "tp1";
tabpage1.text="netabpage1"
tabcontrol1.TabPages.Add(tabpagep1);

How can I set the KEY of the tabpage1?

Was it helpful?

Solution

There is nothing called as TabPage Key.

Key is the name of the TabPage. So, Setting the Name property of your TabPage should work.

TabPage tabpagep1=new TabPage("");
tabpagep1.Name = "tp1";
tabpage1.text="netabpage1";
tabcontrol1.TabPages.Add(tabpagep1);

Later you can read it like

TabPage tp1 = tabcontrol1.TabPages["tp1"];

OTHER TIPS

The doc says it all : The Name property corresponds to the key for a Tab Page

Key is nothing but the Name of Tab Page

if (tabcontrol1.TabPages.ContainsKey("tabpagename")) 
{
   //select existing tab page by "Name" or say "Key"
  tabcontrol1.SelectTab("tabpagename");
}
else
{
   //create new tab page
  TabPage tabpagep1 = new TabPage("");
  tabpagep1.Name = "tabpagename";    
  tabcontrol1.TabPages.Add(tabpagep1);
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top