user1781232
user1781232

Reputation: 669

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.

Upvotes: 4

Views: 4021

Answers (1)

Olivier Jacot-Descombes
Olivier Jacot-Descombes

Reputation: 112437

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();
    }
}

Upvotes: 5

Related Questions