Pregunta

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?

¿Fue útil?

Solución

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).

Otros consejos

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);
}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top