I'm struggling with a simple show/hide function for my main form. I needed to work through different permits, where:
- If I start my app and no one has logged on, the tab page should dissapear,
- At the moment someone has logged on, should show the tab with their respective permits.
I found an answer at this thread and I tried to apply it, but it seems that I miss something.
My code for the function is the followed
public void TabPage1Permission(frmMain formMain, profile myProfile)
{
if (myProfile.Equals(profile.Visitor))
{
formMain.tabPage1.Enabled = false;
formMain.tabPage1.Visible = false;
}
else
{
formMain.tabPage1.Enabled = true;
formMain.tabPage1.Visible = true;
}
}
In this code:
profile is an enum with three values, in which only the value "visitor" doesn't have permits to see TabPage1.
public enum profile { Visitor = 0, Administrator = 1, Editor = 2 };
The function that you see is called in my start code of the main form.
- This function is in a class apart from the main form which I use to administrate the permits according to the requirements of my app.
- I have changed the modifiers in all components inside my main form so I can use them out of the main code class of the form.