eltel2910
eltel2910

Reputation: 345

Open a new form from main form and use WebBrowser

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

Answers (3)

eltel2910
eltel2910

Reputation: 345

Ok. Thank you everyone. To clarify; to make this work I had to:

  1. Select the WebBrowser in the designer. In the Properties window, change the Modifiers property to "Public".
  2. 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

John
John

Reputation: 6268

Select the WebBrowser in the designer. In the Properties window, change the Modifiers property to "Public".

Upvotes: 5

Felix Lebel
Felix Lebel

Reputation: 563

Go in your form's Designer.cs file and change

private WebBrowser webBrowser1;

To this:

public WebBrowser webBrowser1;

Upvotes: 1

Related Questions