lstratman / EasyTabs

Library to enable .NET WinForms apps to easily render a set of tabs in their titlebar space, similar to Chrome, Firefox, Edge, etc.
https://lstratman.github.io/EasyTabs
155 stars 70 forks source link

Adding Programmatically created tab to tablist. #54

Closed LeviBickel closed 3 years ago

LeviBickel commented 3 years ago

I am trying to programmatically add a new tab with a contextmenustrip. I have the menu working and I can create a new window successfully using the following: ` AppContainer app = new AppContainer(); var newtab = new TitleBarTab(app) { Content = new BrowserMain(parameters.LinkUrl) { Text = "New Tab" } }; app.Tabs.Add(newtab); app.SelectedTabIndex = app.SelectedTabIndex + 1;

            TitleBarTabsApplicationContext applicationContext = new TitleBarTabsApplicationContext();
            applicationContext.Start(app);

` It appears this is just creating an entirely new form. I am looking to have this add a tab to the current form though. I have tried the following

` AppContainer app = new AppContainer(); var newtab = new TitleBarTab(app) { Content = new BrowserMain(parameters.LinkUrl) { Text = "New Tab" } }; app.SelectedTabIndex = app.SelectedTabIndex + 1; app.RedrawTabs(); app.Refresh();

` I can't find anything in the documentation or on Google to figure this out. There are no errors in the debugger and when I step through the code it is running through all the steps to create the form but, never shows the tab on the UI to actually navigate to it.

ivanthesexy commented 3 years ago

On the second code, you are not adding it to the tabs list, you are only just creating a new tab. To add new tabs, you must create and add them to the list. Try adding app.Tabs.Add(newtab); after var newtab = new TitleBarTab(app) { Content = new BrowserMain(parameters.LinkUrl) { Text = "New Tab" } };.

LeviBickel commented 3 years ago

@ivanthesexy Thank you for the response. I have tried that and it still isn't working. Please take a look at my repository for the full code specifically this is on the ContextMenuHandler Line 105 : https://github.com/LeviBickel/Chromium-Browser/tree/Fixing-Open-In-New-Tab

AppContainer app = new AppContainer(); var newtab = new TitleBarTab(app) { Content = new BrowserMain(parameters.LinkUrl) { Text = "New Tab" } }; app.Tabs.Add(newtab); app.SelectedTabIndex = app.SelectedTabIndex + 1; app.RedrawTabs(); app.Refresh();

ivanthesexy commented 3 years ago

@ivanthesexy Thank you for the response. I have tried that and it still isn't working. Please take a look at my repository for the full code specifically this is on the ContextMenuHandler Line 105 : https://github.com/LeviBickel/Chromium-Browser/tree/Fixing-Open-In-New-Tab

AppContainer app = new AppContainer(); var newtab = new TitleBarTab(app) { Content = new BrowserMain(parameters.LinkUrl) { Text = "New Tab" } }; app.Tabs.Add(newtab); app.SelectedTabIndex = app.SelectedTabIndex + 1; app.RedrawTabs(); app.Refresh();

Just noticed that you did also created a new container and added your tab to it. Of course it won't work because we didn't added it to our real list. Sorry about that. You need to change app container and use your original TitleBarTabs form instead. You don't need to create another container if you want to add new tabs to an already created container at the beginning. I created a pull request in your project. Please check it.

LeviBickel commented 3 years ago

@ivanthesexy I really appreciate the pull request! I have confirmed the tab is opening but, the URL isn't getting passed over for some reason. I will start investigating this. I really appreciate the help!!

jarno9981 commented 3 years ago

@LeviBickel

How did you add easytabs programmatily

Haltroy commented 3 years ago

How did you add easytabs programmatily

What do you mean by "add easytabs programmatily"? Details on installing EasyTabs are located right below in README of this repository or install the NuGet package from NuGet Package Manager. If you meant to create tabs programmatically, just use CreateTab() in your TitleBarTabs form (the main form, the one that contains the tabs).

LeviBickel commented 3 years ago

@jarno9981 Feel free to fork my Browser repo. https://github.com/LeviBickel/Chromium-Browser

jarno9981 commented 2 years ago

@LeviBickel thank you