Disable Parent Panel, while keeping child panel enabled

anon271334 picture anon271334 · Mar 19, 2011 · Viewed 8.6k times · Source

I have a WinForms app, and I have a massive Panel in it. And inside that Panel is a bunch of stuff, including a second, tiny panel.

When a certain event occurs, I want the massive panel to become Enabled = false, and I still want the tiny panel to be Enabled. Can I do this? I have tried to just re-enable the tiny panel after I've disabled the massive panel, but no worky.

Or, how can I make it so the tiny panel is "on-top of", but not "inside" the massive panel?

I took a wild guess and tried:

tinyPanel.Parent = null;

and tinyPanel.Parent = this;

But, that just makes tinyPanel disappear.

Answer

Cody Gray picture Cody Gray · Mar 19, 2011

No, this is not possible. All child controls are disabled when their parent is disabled. That's simply how Windows works; you're not going to be able to change it.

You need to find a different way of solving your problem. Re-parenting the control is an option, but the way you're trying to do it is incorrect. You need to remove it from the Controls collection for the "massive Panel", and then add it to the Controls collection for your form. Then you will be able to change the enabled state of both controls independently.