TabControl上下文菜单 [英] TabControl Context Menu

查看:89
本文介绍了TabControl上下文菜单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Windows窗体应用程序中,我在TabControl上设置了ContextMenuStrip属性。

In a Windows Forms app I set the ContextMenuStrip property on a TabControl.


  1. 如何告诉用户单击了其他选项卡

  2. 如何限制上下文菜单仅在单击带有标签的顶部选项卡部分时显示,而不在选项卡中的其他位置显示?


推荐答案

不要在TabControl上设置contextMenuStrip属性。而是这样做。连接到tabControl的MouseClick事件,然后手动显示上下文菜单。仅在单击顶部的选项卡本身(而不是实际页面)时才会触发。如果您单击页面,则tabControl不会收到click事件,而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:

public Form1()
{
    InitializeComponent();
    this.tabControl1.MouseClick += new MouseEventHandler(tabControl1_MouseClick);
}

private void tabControl1_MouseClick(object sender, MouseEventArgs e)
{
    if (e.Button == MouseButtons.Right)
    {
        this.contextMenuStrip1.Show(this.tabControl1, e.Location);
    }


}

这篇关于TabControl上下文菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆