上下文菜单父级?
您好,我在标签上添加了一个上下文菜单(c#,winforms)。我的上下文菜单有 3 个子项,我想在单击任一上下文菜单项时显示标签文本。
提前致谢
Hi I added a context menu on label (c#, winforms). my context menu having 3 child items and i want to display label text when i click on any one of context menu items.
thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
ContextMenuStrip
控件有一个SourceControl
属性,它将引用打开它的控件。您可以使用它从控件中提取文本:如果您使用
ContextMenu
而不是ContextMenuStrip
,则代码应如下所示:The
ContextMenuStrip
control has aSourceControl
property, that will have a reference to the control that opened it. You can use that to extract the text from the control:If you instead of a
ContextMenuStrip
use aContextMenu
, the code should look like this:这是一行中最好的:
Its the best in one line:
获取上下文菜单父控件名称
MessageBox.Show(contextMenuStrip1.SourceControl.Name.ToString());
Get Context Menu Parent Control Name
MessageBox.Show(contextMenuStrip1.SourceControl.Name.ToString());