如何在Windows窗体中打开特定选项卡

3

enter image description here

所有这些选项卡都是在Windows窗体中动态创建的。我想在单击按钮时打开特定的选项卡页面。

例如,单击一个按钮(该按钮不是选项卡页按钮,而是其他执行按钮),我想显示选项卡3。

我能够获取选项卡页数,但无法打开特定的选项卡。

private void toolStripButton1_Click(object sender, EventArgs e)
{
    int tabcount = Main_tab.TabCount;
    MessageBox.Show(tabcount.ToString());     
}

2
请阅读 http://meta.stackexchange.com/questions/10647/how-do-i-write-a-good-title - undefined
4个回答

3

别忘了使用 try/catch 来捕获 ArgumentOutOfRangeException 异常。 - undefined

0
你可以通过索引访问它,并调用其方法进行展示。
Main_tab.GetControl(index_of_your_tab);

0
你可以在TabControlControls下找到选项卡。
使用Find按名称查找特定的选项卡。
Main_tab.SelectedTab = (TabPage)Main_tab.Controls.Find("tab3", searchAllChildren: false).First();

嗨Dirk Boer,实际上我的问题被错误编辑了,你能帮我解答上面的问题吗? - undefined
嗯...就我理解你的问题而言,答案仍然适用 :)在调试时,只需查看Main_tab.Controls,你会发现不同的TabPages都在那里。 - undefined

0
private void toolStripButton1_Click(object sender, EventArgs e)

{

  int tabcount = Main_tab.TabCount;

  for (int count = 0; count < class_new_tab.tab_count; count++)
        {
            Main_tab.SelectTab(count);

             //perform tab operation
       }    

}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接