Reputation: 345
I have a main form and I would like to click a button and have a webpage displayed in a new form using the WebBrowser control, this is what I have:
private void button1_Click(object sender, EventArgs e)
{
Form1 MyForm = new Form1();
MyForm.ShowDialog();
MyForm.webBrowser1.Navigate("http://www.twitter.com/");
}
The main forms name is "Twitter", this is the error I get: 'Twitter.Form1.webBrowser1' is inaccessible due to its protection level. Seems simple enough. How can I do this?
Upvotes: 0
Views: 923
Reputation: 345
Ok. Thank you everyone. To clarify; to make this work I had to:
Add MyForm.show();
private void button1_Click(object sender, EventArgs e)
{
Form1 MyForm = new Form1();
MyForm.Show();
MyForm.webBrowser1.Navigate("http://www.twitter.com/");
}
Upvotes: 0
Reputation: 6268
Select the WebBrowser in the designer. In the Properties window, change the Modifiers property to "Public".
Upvotes: 5
Reputation: 563
Go in your form's Designer.cs file and change
private WebBrowser webBrowser1;
To this:
public WebBrowser webBrowser1;
Upvotes: 1