TabControl 上下文菜单
在 Windows 窗体应用程序中,我在 TabControl 上设置 ContextMenuStrip 属性。
- 我如何知道用户单击了除当前所选选项卡之外的选项卡?
- 如何限制上下文菜单仅在单击带有标签的顶部选项卡部分而不是选项卡中的其他位置时显示?
In a Windows Forms app I set the ContextMenuStrip property on a TabControl.
- How can I tell the user clicked a tab other then the one that is currently selected?
- How can I restrict the context menu from showing only when the top Tab portion with the label is clicked, and not elsewhere in the tab?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
上下文菜单的打开事件可以用来解决这两个问题
Opening event of context menu can be used to solve both problems
不必费心在 TabControl 上设置 contextMenuStrip 属性。 不如这样做。 连接到 tabControl 的 MouseClick 事件,然后手动显示上下文菜单。 仅当单击顶部的选项卡本身而不是实际页面时,才会触发此操作。 如果单击页面,则 tabControl 不会收到单击事件,而 TabPage 会收到。 一些代码:
Don't bother setting the contextMenuStrip property on the TabControl. Rather do it this way. Hook up to the tabControl's MouseClick event, and then manually show the context menu. This will only fire if the tab itself on top is clicked on, not the actual page. If you click on the page, then the tabControl doesn't receive the click event, the TabPage does. Some code:
有点晚了,但我已经找到了您问题第一部分的解决方案。 您可以通过向应用程序发送鼠标左键单击来确定右键单击了哪个选项卡。 这将选择选项卡,因此现在您可以使用 TabControl.SelectedTab 属性来获取用户右键单击的选项卡。
A bit late, but I've found a solution for the first part of your question. You can figure out which tab was right-clicked on by sending a left mouse click to the application. This selects the tab, so now you can use the TabControl.SelectedTab property to get the tab that the user right-clicked on.
我正在寻找完全相同问题的解决方案。
在测试了 @nisar 和 @BFree 答案后,我得出了这个结论(我还在表单中的某个面板内有 TabControl`):
I was looking for a solution for the exact same problem.
After testing both @nisar and @BFree answers I came to this (I also had the TabControl` inside a Panel somewhere in the Form):