-1

Lets say I want to open the Google.com in the default browser, then what would I type in there to make sure it always opens in the default browser ?

 private void button1_Click(object sender, Event Args e);
 {

 }
devavx
  • 1,035
  • 9
  • 22
user2334076
  • 11
  • 1
  • 1

2 Answers2

2

You're looking for Process.Start(), which can take an absolute URL (including protocol) and open it with the registered program.

SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964
1

Add System.Diagnostics namespace to you class and then you can use the method below;

Process.Start(string URL);

As you mentioned,to open Google in default browser use this;

Process.Start("www.google.com");

This will always open the URL in user's default browser.

Update

Conside you have a Button named button1 and on its click you want to open Google in the default browser.Click event will look like the below by default.And then add the following code to the event handler;

 private void button1_Click(object sender, EventArgs e);
 {
      DialogResult dr = MessageBox.Show("Do you want to open Google ?", "Someapp", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

      if (dr == DialogResult.Yes)
        {
            Process.Start("www.google.com");
        }

      else
        {
           //React as needed.
        }
 }
devavx
  • 1,035
  • 9
  • 22