如何在 C# 中显示窗体的所有隐藏控件? [英] How to show all hidden controls of a Form in C#?

查看:66
本文介绍了如何在 C# 中显示窗体的所有隐藏控件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 C# 窗体窗口中,假设我有 5 个控件.我只是隐藏了其中一些.当我运行程序时,应该只出现 (Visible=true) 控件.我想单击一个按钮来显示或取消隐藏所有控件.我该怎么做?

In C# form window, say i have 5 controls. I have just hide some of them. When I run the program just the (Visible=true) controls should appear. I want to click a button to appear or unhide all controls. How can i do that?

推荐答案

你可以让它递归,然后如果你有任何面板/组框,他们的孩子也可以看到.

You could make it recursive, then if you have any panels/group boxes their children get made visible too.

public void MakeVisible(Control control)
{
    if(control.HasChildren)
    {
        foreach (Control child in control.Controls)
        {
            MakeVisible(child);
        }
    }
    control.Visible = true;
}

这篇关于如何在 C# 中显示窗体的所有隐藏控件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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