3

According to http://msdn.microsoft.com/en-us/library/system.windows.forms.linklabel.aspx, the LinkLabel class has both a Click event inherited from System.Windows.Forms.Control and a LinkClicked event. From my understanding, Click event will trigger the LinkClicked event.

Why on earth have a LinkClicked event?? What's wrong with the Click event? Are there other ways to trigger LinkClicked besides clicking?

Alexander Bird
  • 38,679
  • 42
  • 124
  • 159

2 Answers2

7

Click will be raised if you click anywhere in the control. LinkClicked will be raised only if you click on a link area. Click will be raised in both cases (before LinkClicked if you click on a link).

Fredrik Mörk
  • 155,851
  • 29
  • 291
  • 343
  • 3
    Also, if the `LinkLabel` has the focus and the user presses Enter, only the `LinkClicked` seemed to be called. – Kevin Doyon Nov 17 '11 at 20:10
3

The LinkClicked event has specific LinkLabelLinkClickedEventArg that allows you to do more than responding to the Click event, which could be fired by the user clicking anywhere on the control not just the link part.

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

    var target = e.Link.LinkData as string;
    System.Diagnostics.Process.Start(target);
}
Peter Kelly
  • 14,253
  • 6
  • 54
  • 63