0

I have a form with labels and other components, picture boxes, panels, etc.. When I am doing Form.enabled = false; (because I have another form on top of it) the labels are not showing even though the visibility of the components is set to true; Any ideas?

I didn't include code because I'm not sure what to include!

Thanks for any help!

Edit: After what Joel Etherton said, I tried using this event:

private void label1_VisibleChanged(object sender, EventArgs e)
{
      label1.Visible = true;
}

This is giving me a StackOverflowException.. maybe this is infinitely trying to override the parent control visibility.. What can I do please?

4

1 回答 1

1

检查元素的父对象(并在树上跟踪它)。通常这是由将父级设置为Visible = false;. 特定控件的可见性设置仍将注册为true,但当页面实际呈现时,它将停止在可见性为 false 的任何父级别生成控件。

编辑:
首先你应该找到问题的根本原因。这与其说是代码问题,不如说是期望问题。控件应该是可见的,但是您已经创建了一个不可能的条件。我认为最好通过尝试找出导致父控件具有错误可见性的条件来为您服务。您很可能会发现强制父级可见性存在逻辑问题,或者您的“可见”控件被放置在错误的根容器中的设计问题。但是,如果您只是想暴力破解父母的可见性,您可以使用递归方法:

private static void SetAllParentVisibility(bool visible, Control ctrl)
{
    ctrl.Visible = visible;
    if (ctrl.Parent != null)
        SetAllParentVisibility(visible, ctrl.Parent);
}

另外,将上述方法视为伪代码。我尚未对其进行测试,并且Control可能需要更改类型才能适应不同的父类型。

于 2012-12-18T15:16:34.857 回答