0

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?

Shiba01
  • 1
  • 1
  • no, I want to put a default browser script or at least open in edge, not explorer – Shiba01 Jan 08 '22 at 16:21
  • @Shiba01 The process.start(url) does start the default browser, not Explorer (unless the user has Internet Explorer as their default browser). – B.O.B. Jan 08 '22 at 16:23
  • @B.O.B. Will this work? `System.Diagnostics.Process.Start("discord.gg/FMxXdmnCxg` – Shiba01 Jan 08 '22 at 16:28
  • Include the protocol (https://) – Martheen Jan 08 '22 at 22:31
  • @Martheen So, I should use ` `private void ButtonDiscord_Click(object sender, EventArgs e) { System.Diagnostics.Process.Start("https://discord.gg/FMxXdmnCxg"); } ` – Shiba01 Jan 09 '22 at 07:46

1 Answers1

0

I would use:

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