禁用父面板,同时保持子面板启用面板

由网友(盲途不遇你)分享简介:我有一个WinForms应用程序,我有一个巨大的面板在里面。而该小组里面是一堆东西,包括第二,微小的面板。I have a WinForms app, and I have a massive Panel in it. And inside that Panel is a bunch of stuff, includ...

我有一个WinForms应用程序,我有一个巨大的面板在里面。而该小组里面是一堆东西,包括第二,微小的面板。

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.

当某个事件发生时,我想了大量的面板,成为启用=假的,我还是想的小面板被激活。我能做到这一点?我试图刚刚重新启用的小面板后,我已经停用​​了大量的面板,但没有worky。

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;

tinyPanel.Parent =这一点;

但是,这只是让tinyPanel消失了。

But, that just makes tinyPanel disappear.

推荐答案

不,这是不可能的。 所有的子控件被禁用时,他们的父母被禁用。这是简单的Windows是如何工作的;你不会是能够改变它。

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.

您需要找到解决您的问题以不同的方式。重新养育控制的是的一种选择,但你要做到这一点是不正确。你需要从Controls收集为大规模面板,然后将其添加到控件集合表单。然后你就可以独立地改变两个控件的启用状态。

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.

阅读全文

相关推荐

最新文章