• C#中用鼠标右键选中tabpage选项卡 并且弹出右键菜单,实现选项卡的关闭



    首先拖一个 ContextMenuStrip 控件

          private void UserSecurityTab_MouseDown(object sender, MouseEventArgs e)
          {
            if (e.Button == MouseButtons.Right)
            {
              for (int i = 0; i < UserSecurityTab.TabPages.Count; i++)
              {
                TabPage tp = UserSecurityTab.TabPages[i];
                if (UserSecurityTab.GetTabRect(i).Contains(new Point(e.X, e.Y)))
                {
                  UserSecurityTab.SelectedTab = tp;
     
                  break;
                }
              }         //实现右键选中选项卡

    //右键选中选项卡 转自:http://www.cnblogs.com/yuandy/archive/2007/07/27/833221.html

              this.UserSecurityTab.ContextMenuStrip = this.UserMenu;  //弹出菜单
            }
          } 

          private void UserSecurityTab_MouseLeave(object sender, EventArgs e)
          {
            this.UserSecurityTab.ContextMenuStrip = null;  //离开选项卡后 取消菜单
          }

          private void closeCToolStripMenuItem_Click(object sender, EventArgs e)
          {
            this.UserSecurityTab.SelectedTab.Dispose();  //关闭当前选中的tabpage页
          }

          private void allCloseAToolStripMenuItem_Click(object sender, EventArgs e)
          {
            foreach(TabPage tp in this.UserSecurityTab.TabPages)
            {
              tp.Dispose();   //关闭全部tabpage 页
            }
          }

          //想实现双击选项卡 关闭TabPage页  直接用MouseDoubleClick 事件
     
          private void UserSecurityTab_MouseDoubleClick(object sender, MouseEventArgs e)
          {
            this.UserSecurityTab.SelectedTab.Dispose();
          }

    说明一下:我这里用的TabControl 不是VS自带的 ,而使用的第三方控件 FlatTabControl  很好用哟,推荐大家用这个............


    本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/wxm3630478/archive/2009/06/24/4293980.aspx

  • 相关阅读:
    电子电路基础复习 —— 电阻
    Linux 网络编程(IO模型)
    Linux 2.6 源码学习-内存管理-buddy算法
    【转】MySQL性能优化的21个最佳实践
    linux 2.6 驱动笔记(三)
    linux 2.6 驱动笔记(二)
    公共代码参考(httpclient)
    linux 2.6 驱动笔记(一)
    bzoj 2401: 陶陶的难题I 数论
    bzoj 3144: [Hnoi2013]切糕 最小割
  • 原文地址:https://www.cnblogs.com/netact/p/2031117.html
Copyright © 2020-2023  润新知