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.
Asked
Active
Viewed 3,972 times
4
-
what do you mean? to `show` the `WinForm` by [LinkLabel.LinkClickedEvent](http://msdn.microsoft.com/en-us/library/system.windows.forms.linklabel.linkclicked(v=vs.71).aspx)? – spajce Jan 22 '13 at 18:24
-
@spajce yes, by clicking on it I want to show a WinForm – user1781232 Jan 22 '13 at 18:33
-
try this, `private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { using (var f = new Form2()) { f.ShowDialog(); } }` – spajce Jan 22 '13 at 18:37
-
video tutorial for linklabel: http://www.youtube.com/watch?v=EyuIAefi9JY – spajce Jan 22 '13 at 18:38
-
@spajce thanks it works. Answer the question so I can accept it – user1781232 Jan 22 '13 at 18:42
-
no problem, its okay, you're welcome.:) – spajce Jan 22 '13 at 18:46
1 Answers
5
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();
}
}

Olivier Jacot-Descombes
- 104,806
- 13
- 138
- 188