user377419
user377419

Reputation: 4999

How to make this open a webbrowser inside a new form

private void button5_Click(object sender, EventArgs e)
{
    if (domainUpDown2.Text == "Battlefield: Bad Company 2")
    {
        Form2 form2 = new Form2();
        form2.ShowDialog();
    }
}                   

All that does is open a new blank form, but i need it to open a new form with a webbrowser in it so i can set it url dependent on the if statement..

Upvotes: 1

Views: 1122

Answers (1)

JYelton
JYelton

Reputation: 36512

Assuming your form2 has a WebBrowser control, and that it has a property you can set like this:

    public Uri WebLocation
    {
        set { webBrowser1.Url = value; }
    }

Then modify your code as follows:

private void button5_Click(object sender, EventArgs e)
{
    Form2 form2 = new Form2();
    if (domainUpDown2.Text == "Battlefield: Bad Company 2")
        form2.WebLocation = new Uri("http://badcompany2.yoursite.com");
    if (domainUpDown2.Text == "Some Other Item")
        form2.WebLocation = new Uri("http://someotheritem.yoursite.com");
    form2.ShowDialog();
}  

Upvotes: 2

Related Questions