Click here to Skip to main content
15,891,409 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a login form and another form. when user is x and password is y I want to show form completely and I do not have problem with this part but when user z with pass t login I wanna he could not see tabpage2 and tabpage3 from form1.

What I have tried:

C#
private void button1_Click(object sender, EventArgs e)
{
    if (textBox1.Text == "x" && textBox2.Text == "123")
    {
        this.Hide();
        Form1 fr1 = new Form1();
        fr1.ShowDialog();
    }
    else
    {
        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
            fr1.ShowDialog();
        }
    }
}
Posted
Updated 14-Mar-16 21:21pm
v2

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

eg.
C#
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();
       }
 
Share this answer
 
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
C#
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...
 
Share this answer
 
v2
Comments
morvarid.bz 26-Mar-16 8:37am    
I read before in Internet that I have to remove them but my problem is I want to remove it from fr1(form1) not loginform then "this" phrase is not applicable for me cause login form does not have any tab.
StM0n 28-Mar-16 9:09am    
Ok... then you have to create a public method to hide/show them accordingly to your use case. Don't just make the methods public, rather create a method which handles this.

Sth like

fr1.hideFirstTab();
fr1.showFirstTab();

or more generic

fr1.hideTabWithThis([Index/Name of the tab]);
fr1.showTabWithThis([Index/Name of the tab]);

To be honest, I would choose an approach that decides itself, what would be neccessary to handle the cases...
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
C#
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);
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900