How to know which link from one and the same linklabel was right clicked in the context menu?

StackOverflow https://stackoverflow.com/questions/15612412

  •  29-03-2022
  •  | 
  •  

문제

I have a LinkLabel to which a context menu strip is attached. This context menu has 2 options: 'Copy hyperlink' or 'Open hyperlink'. There is no problem when there is only one link in the link label. But I can't figure out how you can (if you can) know which link out of the Links property in the link label is right clicked. This is what I have that works for a single link:

private void contextMenuStrip_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
{
    ContextMenuStrip item = sender as ContextMenuStrip;
    LinkLabel tempLink = item.SourceControl as LinkLabel;
    if (e.ClickedItem.Text == "&Open Hyperlink")
    {
        System.Diagnostics.Process.Start(tempLink.Links[0].LinkData.ToString());
    }
    else
    {
        System.Windows.Forms.Clipboard.SetText(tempLink.Links[0].LinkData.ToString());
    }
}

Some help on how to know which of the Links is clicked would be welcome.

도움이 되었습니까?

해결책

Use click event and type folloing code LinkLabel llb = (LinkLabel)sender; now llb.Text has text on which u click the linklabel.

다른 팁

There's a few ways to do that. Quick one is the opening event on the context menu strip. In that sender will be whatever was right clicked on.

You could just store it as say currentLinkLabel, or you could set the Tag property of the menu item maybe

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top