如何获得"真正的" Visible属性的值? [英] How to get the "real" value of the Visible property?

查看:239
本文介绍了如何获得"真正的" Visible属性的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果您设置Windows的Visible属性窗体控件为true,该财产仍然如果任何控件的父窗口被隐藏返回false。有没有办法让的情况下在父窗口是隐藏控件的真实,基本的知名度标志?

If you set the Visible property of a Windows Forms control to true, that property still returns false if any of the control's parent windows are hidden. Is there a way to get the true, underlying visibility flag of the control in case the parent window is hidden?

推荐答案

那么,定时执行的确实的检查了控制堆栈,以确保所有的父母都可见。我知道的唯一办法躲闪,这是欺骗与反思,并要求 GETSTATE(2),但毕竟是易碎的:

Well, the regular implementation does check up the control stack, to ensure that all parents are visible. The only way I know to dodge this is to cheat with reflection, and ask for GetState(2), but that is brittle:

    // dodgy; not recommended
    Panel query;
    Form form = new Form
    {
        Controls = {
            new Panel {
                Visible = false,
                Controls = {
                    (query = new Panel {Visible = true})
                }
            }
        }
    };
    form.Show();

    // this is the dodgy bit...
    bool visible = (bool)typeof(Control)
        .GetMethod("GetState", BindingFlags.Instance | BindingFlags.NonPublic)
        .Invoke(query, new object[] { 2 });

这篇关于如何获得"真正的" Visible属性的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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