How can you determine if Control.Visible is set via a property or if a value is inherited

I need to find a way to determine if the Visible property of a control is set by changing the property or if it inherits its value from its parent. Using Reflector, I find that the functions this.GetVisibleCore () and this.GetState () are internal methods, so I cannot call them.

Widgets are created dynamically, so I don’t want to attach the method to the VisibleChanged event immediately after each widget is created, so you can try to control this property. If I should, I think I will, but I'm looking for something a little more elegant.

Edit

What I really want to know is when I hide the form and close it or create the form, but keep it hidden, that the visible values ​​are false because the form is hidden and which values ​​are false because they were set to false, Again, I don't want to apply a method to every VisibleChanged event of each widget. I just want to somehow read it from a Control object.

+4
source share
1 answer

This is still not very clear, but I assume that the problem is that the getible property of the Visible property returns the actual visibility state of the control. This is not only the last Visible value assigned, but also takes into account whether the parents of the control are visible. In other words, if you have a button in UserControl and UserControl Visible = false, then the Visible button will always be false.

You can override SetVisibleCore () to see if the control will be visible:

public bool CouldBeVisible { get; set; } protected override void SetVisibleCore(bool value) { CouldBeVisible = value; base.SetVisibleCore(value); } 
+2
source

Source: https://habr.com/ru/post/1307190/


All Articles