Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get a button to open a web page?

I've looked everywhere, including the MSDN forums, but no one has even mentioned this or ways to do it. The basic idea is that once a Button is dragged from the toolkit, how do you then link that button to a web page, ie I have a 'Facebook' button, how do I then make it so that when the button is clicked, Facebook opens in a new browser window?

like image 209
Lewis Clark Avatar asked Sep 04 '12 01:09

Lewis Clark


2 Answers

Once you've dragged the button onto the designer, you can double-click on it to open up the Button's Click event handler. This is the code that will get run when the user clicks. You can then add the required logic, ie:

private void button1_Click(object sender, EventArgs e)
{
    // Launch browser to facebook...
    System.Diagnostics.Process.Start("http://www.facebook.com");
}
like image 182
Reed Copsey Avatar answered Oct 28 '22 09:10

Reed Copsey


You can use Process.Start with the desired URL to open the default browser and navigate to the page:

using system.Diagnostics;

private void button1_Click(object sender, EventArgs e)
{
    Process.Start("http://www.YouTube.com");
}
like image 32
sujit jha Avatar answered Oct 28 '22 08:10

sujit jha