上下文菜单相关问题

时间:2011-05-02 17:29:13

标签: c# winforms

假设我的上下文菜单与3标签控件相关联。当我右键单击这些标签时,将出现上下文菜单。我想从上下文菜单中单击事件捕获上下文菜单单击事件所调用的标签。我试过但失败了。

 void MyContextMenu_Click(object sender, EventArgs e)
    {
        if (sender.GetType() == typeof(Label))
        {
            if (((Label)sender).Name.ToUpper() == "LBLACCOUNTREFERENCE")
            {
                Clipboard.Clear();
                Clipboard.SetData(DataFormats.OemText, (object)((Label)sender).Text);
            }
        }
        else
        {
            Clipboard.Clear();
            Clipboard.SetData(DataFormats.OemText, (object)this.localJob.JobPart.OEReference);
        }
    }

请指导我。

1 个答案:

答案 0 :(得分:1)

sender参数指定单击的菜单项 您正在寻找SourceControl property,它为您提供了打开ContextMenuStrip的控件。

检查contextMenu.SourceControl.Text