TabControls与TabPage各有ContextMenuStrip属性来设置其相对应的右键菜单,
但设置过TabPage的ContextMenuStrip属性后,在TabPage区域的任何地方,菜单都可显示,设置过TabControl的ContextMenuStrip也是如此,
我现在想要的效果是在TabControls的TabPage的Text属性区点击时才出现右键菜单,
也就是只有点击标签会出来一个菜单,如有"关闭"之类的.
高人指导!

解决方案 »

  1.   

    菜单不要不帮定
    然后在mousedown事件里面来写
      

  2.   


    mousedown中判断是不是在标签部分吗?
      

  3.   

    有个变通的方法,可以在标签部分加个Panel之类的,右键时判断是不是在Panel内,在Panel内才出菜单
      

  4.   

    设置TabControl的ContextMenuStrip
    不设TabPage的ContextMenuStrip属性
    TabPage里加Panel,Panel.Dock = System.Windows.Forms.DockStyle.Fill.
    判断一下Panel的右键事件!
      

  5.   


    在Panel加没有items的ContextMenuStrip 也可以!!~~~
      

  6.   

    TabControl的ContextMenuStrip 有items
    TabPage的ContextMenuStrip 没有items
    这样就可以了!!!
      

  7.   

        public partial class Form5 : Form
        {
            private System.Windows.Forms.TabControl tabControl1;
            private System.Windows.Forms.TabPage tabPage1;
            private System.Windows.Forms.TabPage tabPage2;
            private System.Windows.Forms.ContextMenuStrip contextMenuStrip1;
            private System.Windows.Forms.ToolStripMenuItem toolStripMenuItem2;
            private System.Windows.Forms.ToolStripMenuItem toolStripMenuItem3;
            private System.Windows.Forms.ToolStripMenuItem toolStripMenuItem4;
            private System.Windows.Forms.ContextMenuStrip contextMenuStrip2;        public Form5()
            {
                InitializeComponent();
                // 
                // contextMenuStrip1
                //contextMenuStrip2有3 个items
                // 
                this.contextMenuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
                this.toolStripMenuItem2,
                this.toolStripMenuItem3,
                this.toolStripMenuItem4});
                this.contextMenuStrip1.Name = "contextMenuStrip1";
                this.contextMenuStrip1.Size = new System.Drawing.Size(77, 70);
                // 
                // toolStripMenuItem2
                // 
                this.toolStripMenuItem2.Name = "toolStripMenuItem2";
                this.toolStripMenuItem2.Size = new System.Drawing.Size(76, 22);
                this.toolStripMenuItem2.Text = "1";
                // 
                // toolStripMenuItem3
                // 
                this.toolStripMenuItem3.Name = "toolStripMenuItem3";
                this.toolStripMenuItem3.Size = new System.Drawing.Size(76, 22);
                this.toolStripMenuItem3.Text = "2";
                // 
                // toolStripMenuItem4
                // 
                this.toolStripMenuItem4.Name = "toolStripMenuItem4";
                this.toolStripMenuItem4.Size = new System.Drawing.Size(76, 22);
                this.toolStripMenuItem4.Text = "3";
                // 
                // contextMenuStrip2
                //contextMenuStrip2没有items
                // 
                this.contextMenuStrip2.Name = "contextMenuStrip2";
                this.contextMenuStrip2.Size = new System.Drawing.Size(61, 4);
                tabControl1.ContextMenuStrip = this.contextMenuStrip1;//TabControl的ContextMenuStrip 有items             tabPage1.ContextMenuStrip = this.contextMenuStrip2;//TabPage的ContextMenuStrip 没有items 
                tabPage2.ContextMenuStrip = this.contextMenuStrip2;//TabPage的ContextMenuStrip 没有items         }
        }