在tabControl中隐藏和显示TabPages [英] Hiding and Showing TabPages in tabControl

查看:124
本文介绍了在tabControl中隐藏和显示TabPages的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试根据用户选择显示或隐藏选项卡.如果用户选择性别为男性,则应显示男性"选项卡中的男性表格;如果用户选择女性,则应在下一个选项卡女性"中显示类似的下一个表格

I am trying to show or hide tabpages as per user choice. If user selects gender male then form for male in a tabpage "male" should be displayed and if user selects female then similar next form should be displayed in next tab "female"

我尝试使用

tabControl1.TabPages.Remove(...)

tabControl1.TabPages.Add(...)

它添加和删除了标签页,但是这样做也会使我对标签页的控件失去控制...我看不到它们.这是什么问题?

It adds and removes the tabpages but doing so will loose my controls on tabpages too... i can't see them back. what's the problem here?

推荐答案

您可以从TabControl.TabPages集合中删除选项卡页,并将其存储在列表中.例如:

You could remove the tab page from the TabControl.TabPages collection and store it in a list. For example:

    private List<TabPage> hiddenPages = new List<TabPage>();

    private void EnablePage(TabPage page, bool enable) {
        if (enable) {
            tabControl1.TabPages.Add(page);
            hiddenPages.Remove(page);
        }
        else {
            tabControl1.TabPages.Remove(page);
            hiddenPages.Add(page);
        }
    }

    protected override void OnFormClosed(FormClosedEventArgs e) {
        foreach (var page in hiddenPages) page.Dispose();
        base.OnFormClosed(e);
    }

这篇关于在tabControl中隐藏和显示TabPages的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆