Windows Develop Bookmark and Share   
 index > Windows Forms General > Setting a button on one tab from another tab
 

Setting a button on one tab from another tab

Hello,

I have a tab control with 2 tabs. On tab1, I have a button that when clicked, should open up a website on a browser control located on tab2. But this is not working. How can I have this button on tab1, interact with the browser control on tab2?

This is how my button is setup on tab1:

Code Block

public void btnHotmail_Click(object sender, EventArgs e)
{
webBrowser.Navigate("http://www.hotmail.com");
}



When I click on this button, it is not loading the website on tab2.
HondaCop  Wednesday, December 26, 2007 6:07 PM

Hi HondaCop,

It would be helpful if you share your solution here. It will help other communities to solve their problem. Below is what I am doing now.

Code Block

TabControlP

public partial class Form2 : Form

{

TabPage tabPage1;

TabPage tabPage2;

WebBrowser webBrowser1;

Button bt;

public Form2()

{

InitializeComponent();

tabPage1 = new TabPage("tabPage1");

tabPage2 = new TabPage("tabPage2");

this.tabControl1.TabPages.AddRange(new TabPage[] { tabPage1, tabPage2 });

bt = new Button();

bt.Location = new Point(20, 50);

bt.Text = "Home";

this.tabPage1.Controls.Add(bt);

bt.Click += new EventHandler(bt_Click);

webBrowser1 = new WebBrowser();

webBrowser1.Dock = DockStyle.Fill;

this.tabPage2.Controls.Add(this.webBrowser1);

}

void bt_Click(object sender, EventArgs e)

{

this.webBrowser1.Navigate("http://www.microsoft.com");

}

}

Thanks.
Rong-Chun Zhang

Rong-Chun Zhang  Friday, December 28, 2007 2:42 AM
Nevermind, got it working.
HondaCop  Wednesday, December 26, 2007 6:15 PM

Hi HondaCop,

It would be helpful if you share your solution here. It will help other communities to solve their problem. Below is what I am doing now.

Code Block

TabControlP

public partial class Form2 : Form

{

TabPage tabPage1;

TabPage tabPage2;

WebBrowser webBrowser1;

Button bt;

public Form2()

{

InitializeComponent();

tabPage1 = new TabPage("tabPage1");

tabPage2 = new TabPage("tabPage2");

this.tabControl1.TabPages.AddRange(new TabPage[] { tabPage1, tabPage2 });

bt = new Button();

bt.Location = new Point(20, 50);

bt.Text = "Home";

this.tabPage1.Controls.Add(bt);

bt.Click += new EventHandler(bt_Click);

webBrowser1 = new WebBrowser();

webBrowser1.Dock = DockStyle.Fill;

this.tabPage2.Controls.Add(this.webBrowser1);

}

void bt_Click(object sender, EventArgs e)

{

this.webBrowser1.Navigate("http://www.microsoft.com");

}

}

Thanks.
Rong-Chun Zhang

Rong-Chun Zhang  Friday, December 28, 2007 2:42 AM

You can use google to search for other answers

Custom Search

More Threads

• TreeView property and Thread-safe calls
• How to expand text box automatically
• Update custom control at design time when property changed
• KeyPreview = true, how do you then detect enter/return?
• ComboBoxStyle
• help witht he about box
• Drag/Drop from OpenFileDialog using C# Windows Application.
• can't access inherited windows form controls
• Transparent form in .NET
• communication between threads