在使用TabControl控件时,希望隐藏其中某个选项卡(即TabPage)。TabPage类明明提供了一个Hide方法,用在代码中却没有任何效果,甚是奇怪。无奈之余,只好考虑另辟途径

方法一:
设置该TabPage的父容器为null 即可,如TabPage.Parent = null 。如需显示该TabPage,设置其父容器为对应的TabControl即可;

        /// <summary>
        /// 通过ShowORHideflag值来判断tabpage在tabcontrol中是否显示或隐藏
        /// </summary>
        /// <param name="tabcontrol"></param>
        /// <param name="tabpage"></param>
        /// <param name="ShowORHideflag">  true为显示,false为隐藏  </param>
        public static void Func_tabPageShowORHide(TabControl tabcontrol,TabPage tabpage, bool ShowORHideflag )
        {
            if (ShowORHideflag)
            {
                tabpage.Parent = tabcontrol;
            }
            else
            {
                tabpage.Parent = null;
            }
        }

 

相关文章:

  • 2021-12-28
  • 2021-05-18
  • 2021-07-14
  • 2022-12-23
  • 2021-11-19
  • 2021-04-21
  • 2021-11-02
  • 2022-02-09
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-26
  • 2022-02-24
相关资源
相似解决方案