开发者

How to hide/block a tab in c#?

I need to know how to make a tab item in a tab control unavailable for a certain kind of user.

The thing goe开发者_StackOverflows that after making 'log in', if the user is not the administrator, he will have one or two tabs unavailable. The admin will have access to the whole system.

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

Thanks in advance


In general:

System.Windows.Forms.TabPage.Enabled= false;

System.Windows.Forms.TabPage.Visible= false;

I prefer next approach:

tabAdmin.Visible = isAdmin;


you can try !

tab.TabPages.Remove(tabToRemove);

How to: Add and Remove Tabs with the Windows Forms TabControl

Or change the Enable and visible state of the tab.

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


EDIT:My answer is generic.

You better make them invisible than unclickable.
Regarding showing the tabs to user,Please check for the role the user is in. Here is my pseudocode..

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


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜