C#:当链接到两个不同的对象时,如何检测上下文菜单的菜单项的调用者是谁?
C#:当链接到两个不同的对象时,如何检测上下文菜单的菜单项的调用者是谁?
我有两个标签,lblOn 和 lblOff。 我将“一个”上下文菜单链接到两个标签,以放弃必须制作两个相同的标签。
我将如何继续找出名为 contextmenu.menuitem 的标签对象? 这样,单击的菜单项就知道它的上下文菜单是由 lblOn 标签还是 lblOffline 调用的?
C#: How to detect who is the caller of a context menu's menu item when linked to two different objects?
I have two labels, lblOn and lblOff. I am linking 'one' contextmenu to both labels to discard having to make two of the same.
How would I go upon finding out which label object called the contextmenu.menuitem? That way the clicked on menuitem knows if it was it it's contextmenu was called by the lblOn label or lblOffline?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
检查
ContextMenuStrip
的SourceControl
属性。Check the
SourceControl
property of theContextMenuStrip
.漠视。 经过更多谷歌搜索后,我找到了一个解决方案+代码示例。
来源:
http://www.tek-tips.com/viewthread.cfm ?qid=1441041&page=8
Disregard. After googling a bit more, I found a solution + code example.
Source:
http://www.tek-tips.com/viewthread.cfm?qid=1441041&page=8
我知道这是很多个月前的问题,但我还没有真正找到
一个简单的答案与代码...
我知道 SLAks 指出了这一点,但我认为其他人需要一个代码示例...
我想知道谁调用了富文本框或标签之间的上下文菜单。
原因是我只想要一个上下文菜单,并希望其中的复制按钮
如果调用者是未选择任何内容的富文本框,则禁用。
这是我的代码:
I know this is a question from many moons ago but I havent really been able to find
a simple answer with code...
I know SLaks kind of pointed it out, but I think others out there need a code sample...
I wanted to know who the called the context menu between either a rich text box or a label.
The reason is I wanted only one context menu and wanted the copy button within it to be
disabled if the caller was the rich text box with nothing selected.
Heres my code:
用这个:
Use this: