0

I have a web browser embedded in my C# application, however, currently, when the user opens the web browser from the application, this opens a new application window (separate to the main application window).

I am trying to add a feature so that the user will be able to open the browser in a new 'tab' inside the application.

I have added a button to my windows form, which, when clicked, I want to display a web browser to the user inside the main application window. I am currently trying to do this by giving the user a 'new tab' button to click, which should open a new tab inside the application window, displaying a web browser to the user. In the menu bar, they should also see a tab for the main application which they were previously viewing, before clicking the 'new tab' button. So their 'tabbed' view will allow them to switch between the main application, and a web browser.

I have added a button to the tool strip of the application window, which is what I want to use to open the browser tab inside the application window:

private void InitializeForm(){
    ...
    newTabButton = new ToolStripButton();
    ...
    menuStrip1.Items.Add(newTabButton);
    ...
    newTabButton.Text = "New Tab";
    newTabButton.Click += new System.EventHandler(newTab);
    ...
}

The code for the newTab() method that I am using to open a new tab when the user clicks the button is:

private void newTab(object sender, EventArgs e){
    TabPage newTab = new TabPage();
    newTab.Text "New Tab";
    tabs.Controls.Add(newTab);
    webBrowser1.Parent = newTab;
    webBrowser1.Dock = DockStyle.Fill;
    webBrowser1.Navigate("www.google.com");
}

However, currently, when I run the application and click the 'New Tab' button, this just displays a completely blank screen inside the application window, and the other controls (menu bar/ buttons) no longer have any effect.

What am I doing wrong here? How can I get a web page contained inside the tab created by the 'new tab' button, and display that to the user?

Noble-Surfer
  • 3,052
  • 11
  • 73
  • 118
  • you could try the solution mentioned here. http://stackoverflow.com/questions/5312275/open-new-web-page-in-new-tab-in-webbrowser-control?rq=1 – Manek May 03 '16 at 12:01
  • Hi, thanks for the link. I've given this a go, but it doesn't seem to do what I want- which is to open up a new tab which can be used to view and interact with websites, the same as in an ordinary browser. – Noble-Surfer May 03 '16 at 13:13

0 Answers0