我需要知道如何使标签控件中的标签项对某种用户不可用。
事情是,在“登录”之后,如果用户不是管理员,他将有一个或两个选项卡不可用。管理员可以访问整个系统。
我只想让标签无法点击。我有什么选择?
提前致谢
答案 0 :(得分:3)
一般来说:
System.Windows.Forms.TabPage.Enabled
= false;
System.Windows.Forms.TabPage.Visible
= false;
我更喜欢下一种方法:
tabAdmin.Visible = isAdmin;
答案 1 :(得分:3)
你可以尝试!
tab.TabPages.Remove(tabToRemove);
How to: Add and Remove Tabs with the Windows Forms TabControl
或更改选项卡的启用和可见状态。
if (!Admin)
{
tab.Visible = false;
tab.Enable = false;
}
答案 2 :(得分:1)
编辑:我的答案是通用的。
你最好让它们看不见,而不是不可点击 关于向用户显示选项卡,请检查用户所处的角色。 这是我的伪代码..
if(User is Administrator)
{
//show the tabs
}
else
{
//dont show the tabs
}
答案 3 :(得分:0)
你可以这样做......
//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();
}