I need to find a way to determine if the Visibl开发者_如何学JAVAe property of a control is set via a property change or if is inheriting it value from its parent. Using the Reflector, I find that the functions this.GetVisibleCore() and this.GetState() are both internal methods so I cannot call them.
The widgets themselves are created dynamically so I do not want to attach a method to the VisibleChanged event just after the creation of each widget so can try to monitor this property. If I have to, I guess I will but I am looking for something just a bit more elegant.
Edit
What I really want to know is when I hide the form and go to close it or build the form but keep it hidden, what Visible values are false because the form is hidden and what values are false because they were set to false. Again I do not want to have to attach a method to each VisibleChanged event of each widget. I just want to somehow read it off the Control object.
It's still not very clear, but I assume that the problem is that the Visible property getter returns the actual visibility state of the control. Which is not just the last assigned value to Visible, it also takes account of whether the parents of the control are visible. In other words, if you've got a button in a UserControl and the UserControl's Visible = false then the button's Visible will always be false as well.
You can override SetVisibleCore() to find out if the control intends to be visible:
public bool CouldBeVisible { get; set; }
protected override void SetVisibleCore(bool value) {
CouldBeVisible = value;
base.SetVisibleCore(value);
}
精彩评论