Reputation: 61
I've been trying so hard to show the tab pages, actually hide the tab pages is working but show i tried everything but nothing successfully here's the code:
this is how i call the form that the user puts his password:
private void adminToolStripMenuItem1_Click(object sender, EventArgs e)
{
Password pss = new Password();
pss.Show();
}
this is the button that have to add the Tab-Page:
private void btnGo_Click(object sender, EventArgs e)
{
if(String.IsNullOrWhiteSpace(txtGo.Text))
{
lblErro.Text = "Type the password.";
return;
}
if(txtGo.Text != Properties.Settings.Default.Pass)
{
lblErro.Text = "Incorrect password.";
return;
}
else
{
this.Close();
MainForm main = new MainForm();
main.operatorToolStripMenuItem1.Checked = false;
main.adminToolStripMenuItem1.Checked = true;
main.accountPermissionsAdm();
}
}
this is the function i created to the account permissions when the user is admin:
public void accountPermissionsAdm()
{
if (!settings)
tabControl_Config.TabPages.Add(tabPage_Report);
if (!pathLoss)
tabControl_Config.TabPages.Add(tabPage_PathLoss);
if (!instrument)
tabControl_Config.TabPages.Add(tabPage_Instrument);
if (!parameters)
mainTabControl.TabPages.Add(tabPage_DefineParameters);
if (!scenario)
mainTabControl.TabPages.Add(tabPage_RunScenario);
if (!customer)
mainTabControl.TabPages.Add(tabPage_CustomerId);
IntPtr h = this.tabControl_Config.Handle;
tabControl_Config.TabPages.Insert(3, tabPage_RunCondition);
}
Upvotes: 0
Views: 1121
Reputation: 2746
UPDATE - after reading your edited question with more code:
Few potential problems:
In btnGo_Click
you are calling this.Close();
which returns, so the rest of the code in this else
statement is unreachable.
Even if you will not call this.Close();
, the code has no practical meaning, as you are creating a new instance of MainForm
but you didn't show it (either by calling main.Show()
or main.ShowDialog()
).
Not sure if that's the flow, but it looks like Password
is a child of your main form (MainForm
). If that's the case, you should change the behavior so that, for example (there are other approaches) Password
will return some value (boolean for example) that the main form needs to be changed (insertion of TabPage
etc.). The change then must be performed on the main form and not from other forms.
Please follow these guidelines and make the changes, or consider of a new design, as it seems very broken to me.
Original answer (how to hide/show tab page)
I'm afraid you can't hide TabPage
. You will have to remove and add it again. For example, like this:
Hide:
this.tabControl1.TabPages.Remove(tabPage1);
Show:
this.tabControl1.TabPages.Add(tabPage1);
The reason is that the Hide()
function will have no effect in this situation, according to MSDN:
TabPage controls are constrained by their container, so some of the properties inherited from the Control base class will have no effect, including Top, Height, Left, Width, Show, and Hide.
Upvotes: 1