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 g
An option that doesn't rely on reflection would be to recurse through the parents of the control hierarchy looking for one with Visible set to false.
EDIT: See comments for significance of code.
var frm2 = new Form {Text = "Form2"};
var lbl = new Label {Visible = true};
frm2.Controls.Add(lbl);
frm2.Show();
var frm1 = new Form {Text = "Form1"};
var lblVis = new Label { Text = lbl.Visible.ToString(), Left = 10, Top = 10};
lbl.VisibleChanged += (sender, args) => MessageBox.Show("Label Visible changed");
var btnShow = new Button {Text = "Show", Left = 10, Top = lblVis.Bottom + 10};
btnShow.Click += (sender, args) =>
{
frm2.Visible = true;
lblVis.Text = lbl.Visible.ToString();
};
var btnHide = new Button {Text = "Hide", Left = 10, Top = btnShow.Bottom + 10};
btnHide.Click += (sender, args) =>
{
frm2.Visible = false;
lblVis.Text = lbl.Visible.ToString();
};
frm1.Controls.AddRange(new Control[] {lblVis, btnShow, btnHide});
Application.Run(frm1);