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
  •  | 
  •  

Pregunta

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.

¿Fue útil?

Solución

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

Otros consejos

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

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top