Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Basic use of Linklabel tool in winforms gives Exception Handling Error

Basic use of Linklabel tool in winforms gives Exception Handling Error

Scheduled Pinned Locked Moved C#
csharpwinformslinqcomgraphics
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    Programmable Physics
    wrote on last edited by
    #1

    This simple code gives Exception Handling Error:

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;

    namespace Label_LinkLabel_TextboxKONTROLLERI
    {
    public partial class Form2 : Form
    {
    public Form2()
    {
    InitializeComponent();
    }

        LinkLabel dynamicLinkLabel = new LinkLabel();
        private void Form2\_Load(object sender, EventArgs e)
        {
            dynamicLinkLabel.BackColor = Color.Red;
            dynamicLinkLabel.ForeColor = Color.Blue;
            dynamicLinkLabel.Text = "I am a Dynamic LinkLabel";
            dynamicLinkLabel.TextAlign = (ContentAlignment)HorizontalAlignment.Center;
            dynamicLinkLabel.Text += " Appended text";
            dynamicLinkLabel.Name = "DynamicLinkLabel";
            dynamicLinkLabel.Font = new Font("Georgia", 16);
            Controls.Add(dynamicLinkLabel);
            dynamicLinkLabel.Name = "DynamicLinkLabel";
            string name = dynamicLinkLabel.Name;
            dynamicLinkLabel.Location = new Point(20, 150);
            dynamicLinkLabel.Height = 40;
            dynamicLinkLabel.Width = 300;
            dynamicLinkLabel.BackColor = Color.Red;
            dynamicLinkLabel.ForeColor = Color.Blue;
            dynamicLinkLabel.BorderStyle = BorderStyle.FixedSingle;
    
            dynamicLinkLabel.ActiveLinkColor = Color.Orange;
            dynamicLinkLabel.VisitedLinkColor = Color.Green;
            dynamicLinkLabel.LinkColor = Color.RoyalBlue;
            dynamicLinkLabel.DisabledLinkColor = Color.Gray;
    
            dynamicLinkLabel.LinkArea = new LinkArea(0, 22);
            dynamicLinkLabel.Links.Add(24, 9, "http://www.c-sharpcorner.com");
            dynamicLinkLabel.LinkClicked += new LinkLabelLinkClickedEventHandler(LinkedLabelClicked);
        }
        private void LinkedLabelClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            dynamicLinkLabel.LinkVisited = true;
            System.Diagnostics.Process.Start("http://www.c-sharpcorner.com");
        }
    }
    

    }
    The code above has been taken from this website: https://www.c-sharpcorner.com/UploadFile/mahesh/linklabel-in-C-Sharp/

    Here is the exception:
    System.ComponentModel.Win32Exception: 'An error occurred trying to start process 'http://www.c-sharpcorner.com' with working directory 'C:\Users\LENOVO\De

    C Richard DeemingR 2 Replies Last reply
    0
    • P Programmable Physics

      This simple code gives Exception Handling Error:

      using System;
      using System.Collections.Generic;
      using System.ComponentModel;
      using System.Data;
      using System.Drawing;
      using System.Linq;
      using System.Text;
      using System.Threading.Tasks;
      using System.Windows.Forms;

      namespace Label_LinkLabel_TextboxKONTROLLERI
      {
      public partial class Form2 : Form
      {
      public Form2()
      {
      InitializeComponent();
      }

          LinkLabel dynamicLinkLabel = new LinkLabel();
          private void Form2\_Load(object sender, EventArgs e)
          {
              dynamicLinkLabel.BackColor = Color.Red;
              dynamicLinkLabel.ForeColor = Color.Blue;
              dynamicLinkLabel.Text = "I am a Dynamic LinkLabel";
              dynamicLinkLabel.TextAlign = (ContentAlignment)HorizontalAlignment.Center;
              dynamicLinkLabel.Text += " Appended text";
              dynamicLinkLabel.Name = "DynamicLinkLabel";
              dynamicLinkLabel.Font = new Font("Georgia", 16);
              Controls.Add(dynamicLinkLabel);
              dynamicLinkLabel.Name = "DynamicLinkLabel";
              string name = dynamicLinkLabel.Name;
              dynamicLinkLabel.Location = new Point(20, 150);
              dynamicLinkLabel.Height = 40;
              dynamicLinkLabel.Width = 300;
              dynamicLinkLabel.BackColor = Color.Red;
              dynamicLinkLabel.ForeColor = Color.Blue;
              dynamicLinkLabel.BorderStyle = BorderStyle.FixedSingle;
      
              dynamicLinkLabel.ActiveLinkColor = Color.Orange;
              dynamicLinkLabel.VisitedLinkColor = Color.Green;
              dynamicLinkLabel.LinkColor = Color.RoyalBlue;
              dynamicLinkLabel.DisabledLinkColor = Color.Gray;
      
              dynamicLinkLabel.LinkArea = new LinkArea(0, 22);
              dynamicLinkLabel.Links.Add(24, 9, "http://www.c-sharpcorner.com");
              dynamicLinkLabel.LinkClicked += new LinkLabelLinkClickedEventHandler(LinkedLabelClicked);
          }
          private void LinkedLabelClicked(object sender, LinkLabelLinkClickedEventArgs e)
          {
              dynamicLinkLabel.LinkVisited = true;
              System.Diagnostics.Process.Start("http://www.c-sharpcorner.com");
          }
      }
      

      }
      The code above has been taken from this website: https://www.c-sharpcorner.com/UploadFile/mahesh/linklabel-in-C-Sharp/

      Here is the exception:
      System.ComponentModel.Win32Exception: 'An error occurred trying to start process 'http://www.c-sharpcorner.com' with working directory 'C:\Users\LENOVO\De

      C Offline
      C Offline
      CHill60
      wrote on last edited by
      #2

      A URL is not a process. Look at the documentation Process.Start Method (System.Diagnostics) | Microsoft Learn[^] And if code from another site is "broken" then you should really be posting the question on the site you got it from Edit: Assuming the code works for the original author, then I can only assume he has some default set so that his preferred browser automatically opens but you do not. Try using the name of your favourite browser as the process name, passing that URL as a parameter

      1 Reply Last reply
      0
      • P Programmable Physics

        This simple code gives Exception Handling Error:

        using System;
        using System.Collections.Generic;
        using System.ComponentModel;
        using System.Data;
        using System.Drawing;
        using System.Linq;
        using System.Text;
        using System.Threading.Tasks;
        using System.Windows.Forms;

        namespace Label_LinkLabel_TextboxKONTROLLERI
        {
        public partial class Form2 : Form
        {
        public Form2()
        {
        InitializeComponent();
        }

            LinkLabel dynamicLinkLabel = new LinkLabel();
            private void Form2\_Load(object sender, EventArgs e)
            {
                dynamicLinkLabel.BackColor = Color.Red;
                dynamicLinkLabel.ForeColor = Color.Blue;
                dynamicLinkLabel.Text = "I am a Dynamic LinkLabel";
                dynamicLinkLabel.TextAlign = (ContentAlignment)HorizontalAlignment.Center;
                dynamicLinkLabel.Text += " Appended text";
                dynamicLinkLabel.Name = "DynamicLinkLabel";
                dynamicLinkLabel.Font = new Font("Georgia", 16);
                Controls.Add(dynamicLinkLabel);
                dynamicLinkLabel.Name = "DynamicLinkLabel";
                string name = dynamicLinkLabel.Name;
                dynamicLinkLabel.Location = new Point(20, 150);
                dynamicLinkLabel.Height = 40;
                dynamicLinkLabel.Width = 300;
                dynamicLinkLabel.BackColor = Color.Red;
                dynamicLinkLabel.ForeColor = Color.Blue;
                dynamicLinkLabel.BorderStyle = BorderStyle.FixedSingle;
        
                dynamicLinkLabel.ActiveLinkColor = Color.Orange;
                dynamicLinkLabel.VisitedLinkColor = Color.Green;
                dynamicLinkLabel.LinkColor = Color.RoyalBlue;
                dynamicLinkLabel.DisabledLinkColor = Color.Gray;
        
                dynamicLinkLabel.LinkArea = new LinkArea(0, 22);
                dynamicLinkLabel.Links.Add(24, 9, "http://www.c-sharpcorner.com");
                dynamicLinkLabel.LinkClicked += new LinkLabelLinkClickedEventHandler(LinkedLabelClicked);
            }
            private void LinkedLabelClicked(object sender, LinkLabelLinkClickedEventArgs e)
            {
                dynamicLinkLabel.LinkVisited = true;
                System.Diagnostics.Process.Start("http://www.c-sharpcorner.com");
            }
        }
        

        }
        The code above has been taken from this website: https://www.c-sharpcorner.com/UploadFile/mahesh/linklabel-in-C-Sharp/

        Here is the exception:
        System.ComponentModel.Win32Exception: 'An error occurred trying to start process 'http://www.c-sharpcorner.com' with working directory 'C:\Users\LENOVO\De

        Richard DeemingR Offline
        Richard DeemingR Offline
        Richard Deeming
        wrote on last edited by
        #3

        Your errors suggest you're using .NET Core or .NET 5, 6, or 7. Unlike in the .NET Framework, .NET Core and .NET do not set the UseShellExecute to true by default - you need to specify it explicitly:

        private void LinkedLabelClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
        dynamicLinkLabel.LinkVisited = true;
        System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo
        {
        FileName = "http://www.c-sharpcorner.com",
        UseShellExecute = true,
        });
        }


        "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

        "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups