隐藏C#中其他表单的tabpages [英] Hide tabpages from another form in C#
本文介绍了隐藏C#中其他表单的tabpages的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个登录表单和另一个表单。当用户是x而密码是y我想完全显示表格而且我没有这个部分的问题但是当用户z通过t登录我想要他从form1看不到tabpage2和tabpage3。
我尝试了什么:
I have a login form and another form. when user is x and password is y I want to show form completely and I do not have problem with this part but when user z with pass t login I wanna he could not see tabpage2 and tabpage3 from form1.
What I have tried:
private void button1_Click(object sender, EventArgs e)
{
if (textBox1.Text == "x" && textBox2.Text == "123")
{
this.Hide();
Form1 fr1 = new Form1();
fr1.ShowDialog();
}
else
{
if (textBox1.Text == "z" && textBox2.Text == "t")
{
this.Hide();
Form1 fr1 = new Form1();
//how can I hide tabpage2 and tabpage3 on form1(fr1) for this user
fr1.ShowDialog();
}
}
}
推荐答案
你的问题,我猜是,那个.Hide()
和.Visible = false
没有假设...
您必须从控件的TabPages
中删除它...这样的事情
Your problem, I guess, was, that.Hide()
and.Visible = false
didn't work out as assumed...
You have to remove it from theTabPages
of your control... something like this
if (this.tabControl1.TabPages.Contains(this.tabPage2))
this.tabControl1.TabPages.Remove(this.tabPage2);
else
this.tabControl1.TabPages.Add(this.tabPage2);
请记住,这只是一个提示......不要只是复制和粘贴它......
Remember, this is just a hint... don't just copy&paste it...
您好
您无法隐藏Windows窗体应用程序中的标签。您应该根据您的用户添加和删除标签
例如。
Hi
U cant hide tabs in windows forms application.U should add and remove tabs according to your users
eg.
if (textBox1.Text == "z" && textBox2.Text == "t")
{
this.Hide();
Form1 fr1 = new Form1();
//how can I hide tabpage2 and tabpage3 on form1(fr1) for this user
tabControl1.TabPages.Remove(tabpage2);
tabControl1.TabPages.Remove(tabpage3 );
fr1.ShowDialog();
}
不,这不存在。您必须删除选项卡并在需要时重新添加。或者使用不同的(第三方)标签控件。
可能类似于以下代码
No, this doesn't exist. You have to remove the tab and re-add it when you want it. Or use a different (3rd-party) tab control.
may be like below code
private System.Windows.Forms.TabControl _tabControl;
private System.Windows.Forms.TabPage _tabPage1;
private System.Windows.Forms.TabPage _tabPage2;
...
// Initialise the controls
...
// "hides" tab page 2
_tabControl.TabPages.Remove(_tabPage2);
// "shows" tab page 2
if (_tabControl.TabPages.Contains(_tabPage2))
{
_tabControl.TabPages.Add(_tabPage2);
}
这篇关于隐藏C#中其他表单的tabpages的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文