问题描述
我在我的获胜表格上使用TabControl.
另外,我能够使用添加和删除方法隐藏或显示选项卡页面,但不知道如何检查选项卡页面是否可见.
这是示例
可见2个标签页(tabpage1名称="Page1"和tabpage2名称="Page2")
当我想添加Page2时,首先我要检查Page2是否真正可见.如果是,那么我将只关注相同的内容,否则我将添加相同的内容.
如果有人可以帮助我,请如何做...
谢谢
Almir
Hi,
i''m using TabControl on my win form.
Also, i''m able to hide or show tab pages using add and remove method but don''t know how to check if tabpage is visible .
Here is example
2 tab pages visible (tabpage1 name = "Page1" and tabpage2 name ="Page2")
When I want to add Page2, first I want to check if Page2 is actually visible . If yes then I would only set focus on the same otherwise I would add the same.
Please if someone can help me how to make this working...
Thanks
Almir
推荐答案
foreach (TabPage tp in myTabControl.TabPages)
{
if (tp.Text == "Page2")
{
...
break;
}
}
或者,如果您有整个TabPage可用,则可以查看TabPage.Name属性,或使用TabControl.TabPages.Contains方法.
谢谢
我按照您的建议进行了以下操作
Or you could look at the TabPage.Name property, or use the TabControl.TabPages.Contains method if you have the whole TabPage available.
"Thanks
i followed your proposal as follows
if (customTabControl1.TabPages.Contains(Page2))
{
customTabControl1.SelectedTab = Page2;
}
else
{
customTabControl1.TabPages.Add(Page2);
customTabControl1.SelectedTab = Page2;
}
但是当我尝试选择添加的标签页Page2时出现以下错误
无法访问已处置的对象
您能帮我解决问题吗?
谢谢"
当您尝试通过从选项卡页列表中删除它来隐藏Page2时,您没有保留对其的引用,因此Garbage Collector已在该页面上进行了处理-您无法做很多事情,删除时除了保留参考(无论如何还是个好主意).
您使用什么代码显示/隐藏标签页?
but I get the following error when I try to Select added tabpage Page2
cannot access a disposed object
Can you help me to solve the problem.
Thanks"
When you tried to hide Page2 by removing it from the list of tab pages, you didn''t keep a reference to it, so the Garbage Collector has Disposed on the page - there isn''t a whole lot you can do about that, other than keep a reference (which would be a good idea anyway) when you remove it.
What code are you using to show / hide tab pages?
private void tabacc_Receivable_Selected(object sender, TabControlEventArgs e)
{
if (e.TabPage == tabacc_Client)
{
dgvacc_ClientRefresh();
}
if (e.TabPage == tabEditNew)
{
LoadRecordInformation();
}
if (e.TabPage == tabClientBalance)
{
}
}
if (customTabControl1.TabPages.Contains(Page2))
{
customTabControl1.SelectedTab = Page2;
}
else
{
customTabControl1.TabPages.Add(Page2);
customTabControl1.SelectedTab = Page2;
}
但是当我尝试选择添加的标签页Page2时出现以下错误
无法访问已处置的对象
您能帮我解决问题吗?
谢谢
but I get the following error when I try to Select added tabpage Page2
cannot access a disposed object
Can you help me to solve the problem.
Thanks
这篇关于检查标签页在tabcontrol中是否可见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!