How to hide / lock a tab in C #?

I need to know how to make a tab control in a tab control inaccessible to a specific user.

The fact is that after creating a "login", if the user is not an administrator, he will have one or two tabs inaccessible. The administrator will have access to the entire system.

I just want to make the tabs un-clickable. What are my options?

Thanks in advance

+2


a source to share


4 answers


Generally:

System.Windows.Forms.TabPage.Enabled

= false;

System.Windows.Forms.TabPage.Visible

= false;



I prefer the following approach:

tabAdmin.Visible = isAdmin;

      

+3


a source


you can try!

tab.TabPages.Remove(tabToRemove);

      

How to add and remove tabs with TabControl Windows Forms



Or change the enable and visibility state of the tab.

if (!Admin)
{
   tab.Visible = false;
   tab.Enable = false;
}

      

+3


a source


EDIT . My answer is general.

It is better to make them invisible than unattractive.
Regarding the display of tabs for the user, check the role the user is in. Here is my pseudocode.

if(User is Administrator)
{
//show the tabs
}
else
{
//dont show the tabs
}

      

+1


a source


You can do it like this:

//Within Window_Loaded routine...
//Check a boolean setting you created
//If setting is set to 'not have the tab enabled' set that tabitem to hidden
if (Settings.Default.CheckConverterTabEnabled == false)
{
    CheckConverterTab.Visibility = Visibility.Hidden;
}
//Otherwise, run that tab window loaded routine
else
{
    CheckConverterWindowLoaded();
}

      

0


a source







All Articles