How to make a link open in the default browser in C#?

715 Views Asked by At

I want to make a button that puts users in their default browser in Visual Studio '19 I'm making a C# windows form application, and I have a button to a discord server for users Does anyone have an answer? Currently I use

        private void linkLabel2_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {

        Call: OpenUrl("discord.gg/FMxXdmnCxg");
        }

        private static void OpenUrl(string url)
        {
            Process pro = new Process();
            pro.StartInfo.FileName = "msedge.exe";
            pro.StartInfo.Arguments = url;
            pro.Start();
        }

Should I keep with this or should I change it?

1

There are 1 best solutions below

2
Barni On

I would use:

static void OpenUrl(string url)
{
    ProcessStartInfo processInfo = new ProcessStartInfo();
    processInfo.FileName = url;
    processInfo.UseShellExecute = true;
    Process.Start(processInfo);
}