0
Reply

Web Browser Tab Control problem

Lewis Cowan

Lewis Cowan

Dec 5 2010 10:01 AM
8.5k
I'm trying to make a simple web browser with tab support and am having difficulty with getting pages to load in the right tabs.
I can make new windows and tabs and switch between them, however the web page typed in the address bar always loads in tab 0. I've never really used tab controls before and I'm kind of learning as I go.

I think I need somehow to almost dynamically name each new instance of webBrowser so they can be accessed individually but I don't know how to go about something like that.

Here's what I've got so far

         private void toolStripTextBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == 13)
{
int currentTab = tabControl1.SelectedIndex;
MessageBox.Show(currentTab.ToString());
// tabControl1.SelectedTab.
webBrowser1.Navigate(toolStripTextBox1.Text);
// Identify selected tab from tabControl1 and use this
// to load the requested URL in the current tab's web browser
}
}

private void Form1_Load(object sender, EventArgs e)
{
webBrowser1.Navigate("http://www.google.co.uk");
}

private void newWindowToolStripMenuItem_Click(object sender, EventArgs e)
{
Form nextWindow = new Form1();
nextWindow.Show();
}

private void newTabToolStripMenuItem_Click(object sender, EventArgs e)
{
TabPage nextTab = new TabPage("Google");
tabControl1.TabPages.Add(nextTab);
tabControl1.SelectedTab = nextTab;
WebBrowser webBrowser1 = new WebBrowser();
nextTab.Controls.Add(webBrowser1);
webBrowser1.Dock = DockStyle.Fill;
webBrowser1.Navigate("http://www.google.co.uk");


}

Thank you for any help

Lewis