简体   繁体   中英

difference between LinkLabel.Click and LinkLabel.LinkClicked event?

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?

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM