我正在使用ContextMenuStrip进行多个控件,我试图找出获得实际点击的控件以打开上下文菜单的最佳方法.发送者只提供ToolStripMenuItem引用,该引用具有引用ContextMenuStrip的Owner属性,但我无法弄清楚如何判断单击来自哪个控件.必须有一个简单的方法来检查这个,对吗?我在ToolStripMenuItem的click事件中检查它.
Friend WithEvents mnuWebCopy As System.Windows.Forms.ToolStripMenuItem ... Private Sub mnuWebCopy_Click(ByVal sender As Object,ByVal e As System.EventArgs) Handles mnuWebCopy.Click
我发现了一个关于这个的similar post,但是提到了使用我在这里看不到的SourceControl属性.
我正在使用Visual Studio 2008,VB.Net winforms.
Private Sub mnuWebCopy_Click(ByVal sender As Object,ByVal e As System.EventArgs) Handles mnuWebCopy.Click Dim myItem As ToolStripMenuItem = CType(sender,ToolStripMenuItem) Dim cms As ContextMenuStrip = CType(myItem.Owner,ContextMenuStrip) MessageBox.Show(cms.SourceControl.Name) End Sub