且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

隐藏C#中其他表单的tabpages

更新时间:2023-12-06 17:32:40

你的问题,我猜是,那个 .Hide() .Visible = false 没有假设...



您必须从控件的 TabPages 中删除​​它...这样的事情

Your problem, I guess, was, that .Hide() and .Visible = false didn't work out as assumed...

You have to remove it from the TabPages of your control... something like this
if (this.tabControl1.TabPages.Contains(this.tabPage2))
    this.tabControl1.TabPages.Remove(this.tabPage2);
else
    this.tabControl1.TabPages.Add(this.tabPage2);



请记住,这只是一个提示......不要只是复制和粘贴它......


Remember, this is just a hint... don't just copy&paste it...


您好


您无法隐藏Windows窗体应用程序中的标签。您应该根据您的用户添加和删除标签



例如。
Hi
U cant hide tabs in windows forms application.U should add and remove tabs according to your users

eg.
if (textBox1.Text == "z" && textBox2.Text == "t")
       {
           this.Hide();
           Form1 fr1 = new Form1();
          //how can I hide tabpage2 and tabpage3 on form1(fr1) for this user
tabControl1.TabPages.Remove(tabpage2);
tabControl1.TabPages.Remove(tabpage3 );
           fr1.ShowDialog();
       }


不,这不存在。您必须删除选项卡并在需要时重新添加。或者使用不同的(第三方)标签控件。

可能类似于以下代码

No, this doesn't exist. You have to remove the tab and re-add it when you want it. Or use a different (3rd-party) tab control.
may be like below code
private System.Windows.Forms.TabControl _tabControl;
private System.Windows.Forms.TabPage _tabPage1;
private System.Windows.Forms.TabPage _tabPage2;

...

// Initialise the controls

...

// "hides" tab page 2
_tabControl.TabPages.Remove(_tabPage2);

// "shows" tab page 2
if (_tabControl.TabPages.Contains(_tabPage2))
{
    _tabControl.TabPages.Add(_tabPage2);
}