winformsvisual-studio-2010c#-4.0hyperlinklinklabel

Can I use LinkLabel on Visual Studios to link to a windows form?


I have been looking up on google to find out how to use linklabel to link to a Windows Form. All the tutorials that I've come across only link you to a URL or you local disk. Any help? I don't want to use buttons.


Solution

  • Use the LinkLabel as you would be using a button, by executing code in the click event. Open the form (or bring it to the front if it is alreay open) programmatically when the user clicks the label. You will not be able to set an URL to a form.

    private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
    {
        Form2 form2 = Application.OpenForms.OfType<Form2>().FirstOrDefault();
        if (form2 == null) {
            form2 = new Form2();
            form2.Show();
        } else {
            form2.BringToFront();
        }
    }