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

查看:31
本文介绍了在 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天全站免登陆