• 0

Need basic .NET LinkLabel help


Question

I am using Microsoft Visual Studio Community 2015.

 

I have added a LinkLabel ("LinkLabel1") and changed the text to read www.neowin.net.

 

Now how do I get it to actually go to www.neowin.net when it's clicked?

 

I can't find the option in the Properties dock.

 

I am a beginner - go easy on me!

Link to comment
Share on other sites

3 answers to this question

Recommended Posts

  • 0

There is an event you have to implement called Link_Clicked:

 

public Form1()
    {
        // Create the LinkLabel.
        this.linkLabel1 = new System.Windows.Forms.LinkLabel();

        // Configure the LinkLabel's location. 
        this.linkLabel1.Location = new System.Drawing.Point(34, 56);
        // Specify that the size should be automatically determined by the content.
        this.linkLabel1.AutoSize = true;

        // Add an event handler to do something when the links are clicked.
        this.linkLabel1.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.linkLabel1_LinkClicked);

        // Set the text for the LinkLabel.
        this.linkLabel1.Text = "https://www.neowin.net";

        // Set up how the form should be displayed and add the controls to the form.
        this.ClientSize = new System.Drawing.Size(292, 266);
        this.Controls.AddRange(new System.Windows.Forms.Control[] { this.linkLabel1 });
        this.Text = "Simple Link Label Example";
    }

    private void linkLabel1_LinkClicked(object sender, System.Windows.Forms.LinkLabelLinkClickedEventArgs e)
    {
        // Specify that the link was visited.
        this.linkLabel1.LinkVisited = true;

        // Navigate to a URL.
        System.Diagnostics.Process.Start("https://www.neowin.net");
    }
Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.