• C# Winform TabControl 双击关闭TabPage


    在使用TabControl控件时,需要考虑自动创建的TabPage页实现——关闭功能

    思路一:自定义TabControl控件,添加关闭按钮

    思路二:TabControl控件TabPage显示ToolTip属性(例如双击关闭)

    此处,解释思路二,实现方式

    操作步骤:

    第一步:TabControl添加多个TabPage页,ShowToolTip=true;

    第二步:TabPage,ToolTipText="双击关闭页签";

    第三步:实现双击事件MouseDoubleClick,如下所示:

     private void tabControl1_MouseDoubleClick(object sender, MouseEventArgs e)
            {
                //TabPage page = sender as TabPage;
                //this.tabControl1.TabPages.Remove(page);
                tabControl1.TabPages.RemoveAt(tabControl1.SelectedIndex);
            }
    

    动态添加TabPage参考如下

    AddTabPage("DirectRegisterForm", "登记中心");

     private void AddTabPage(string formName, string formText)
            {
                TabPage page = this.tabContent.TabPages[formName];
                if (page != null)
                {
                    tabContent.SelectedTab = page;
                    page.Select();
                    return;
                }
    
                TabPage tab = new TabPage();
                tab.Name = formName;
                tab.Text = formText;
                Form form = GetForm(formName);
                form.TopLevel = false;
                form.FormBorderStyle = FormBorderStyle.None;
                form.Dock = DockStyle.Fill;
    
                tab.Controls.Add(form);
                tabContent.TabPages.Add(tab);
                tabContent.SelectedTab = tab;
                form.Show();
            }
    
      private Form GetForm(object itemName)
            {
                try
                {
                    this.Cursor = Cursors.WaitCursor;
    
                    Assembly assembly = Assembly.GetExecutingAssembly();
                    var path = "ZB.QueueSys.View." + itemName.ToString();
                    Form form = assembly.CreateInstance(path) as Form;
                    return form;
                }
                catch { return null; }
                finally
                {
                    this.Cursor = Cursors.Default;
                }
            }
    

      

      

      

  • 相关阅读:
    天堂Lineage(單機版)從零開始架設教學 Installing Lineage 3.52 Server
    /dev/random vs /dev/urandom
    Linux Interactive Exploit Development with GDB and PEDA
    Python : Polymorphism
    Python : Data Encapsulation
    Using Keyboard Navigation
    Capture pictures using Jpython
    Java并发编程:volatile关键字解析
    java 资料收集
    解决ubuntu侧边栏固定应用单击无反应的问题
  • 原文地址:https://www.cnblogs.com/YYkun/p/11466743.html
Copyright © 2020-2023  润新知