lstratman/EasyTabs

How to make new tab?

Closed this issue · 3 comments

So I'm using this, works tremendously, however the only issue I encountered is how do I make a new tab ?

So, I have my regular tab, and when I make a new tab by clicking the + button it creates a replica of the main tab. , like it suppose to do, however, how do I fix it so when I click like 'Configurations' it shows a different page?

I've looked over the 'Similar Issues' and none of which is helpful to me.

Well, you have to implement it by yourself.
Duplicate the CreateTab() in same for but add a new parameter. Use if for that parameter.

public void CreateTab(bool Config)
{
TitleBarTab newTab;
    if (Config) 
    {
      newTab = new TitleBarTab(this)
        {
            Content = new frmConfig
        };
       this.Tabs.Add(newTab);
     } else {
        newTab = new TitleBarTab(this)
        {
            Content = new Form1
        };
        this.Tabs.Add(newTab);
     }
        
}

Also, you can use parameters for those Contents too.

public void CreateTab(bool Config)
{
TitleBarTab newTab;
      newTab = new TitleBarTab(this)
        {
            Content = new Form1(Config)
        };
        this.Tabs.Add(newTab);
}

Second one requires new parameters for the main tab form

public class tabform : Form 
{
    bool ConfigurationMode = false;
    public TitleBarTabs ParentTabs => (ParentForm as TitleBarTabs);
    public frmMain mainform()
    {
     return ((frmMain)this.ParentTabs);
    }
    public tabform (bool isConfig) 
    {
        ConfigurationMode = isConfig;
        // rest of the code....

You can call it like this:

mainform().Invoke(new Action(() => 
{
 mainform().CreateTab(true); //Creates tab
        //NOTE: You can put more codes in here if you want.
            }));

or (for just creating tabs, no more extra codes to Invoke())

mainform().Invoke(new Action(() => mainform().CreateTab(true)));
Detect if your main form is not disposed or closing before executing Invoke commands.

@Haltroy is right on the money (thanks!), so I'm closing this out.

I didn't really understand how to add a new tab with a different form