如何使窗体上的所有控件?

编程入门 行业动态 更新时间:2024-10-25 06:27:55
本文介绍了如何使窗体上的所有控件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

目前我最有推出禁用我的窗体的控件,因为直到文件被加载,你不能使用它们。然而,一旦文件被加载控件应该会启用。

Currently I have most of my form's controls disabled at launch because you cannot use them until a file is loaded. However, once the file is loaded the controls should become enabled.

我是使用绑定,但我不认为他们是一个很好的解决方案。首先,它是不必要的复杂性。其次,您不能使用绑定的一切。例如,MenuStrip中的项目不能有自己的Enabled属性绑定到fileLoaded财产。只有整个菜单可以,我不希望禁用在启动整个菜单,只有对文件进行操作的某些菜单操作。

I was using bindings but I don't think they're a good solution. For one, it is unnecessary complexity. Secondly, you cannot use bindings for everything. For example, MenuStrip items cannot have their Enabled property bound to the fileLoaded property. Only the entire menu can and I don't want to disable the entire menu at launch, only certain menu operations that operate on the file.

我真的只是寻找一种方式,以使一切。当被问及最,将有这样的回答:

I'm really just looking for a way to enable EVERYTHING. Most when asked that would answer with this:

foreach (Control c in Controls) { c.Enabled = true; }

然而,这并不用于使其他控件内的MenuStrip项或控制工作(如面板或自定义控制)。因此它不会使容器内的滚动条。

However, that does not work for enabling MenuStrip items or controls within other controls (like a Panel or custom control). Therefore it would not enable scrollbars within containers.

我想我可以使用该行并手动启用一切,但我可​​以永远只是手动的启用一切。我正在寻找一种方法来自动启用的所有的

I suppose I could use that line and manually enable everything else but I could have always just manually enabled everything. I'm looking for a way to automatically enable everything.

推荐答案

递归

private void enableControls(Control.ControlCollection Controls) { foreach (Control c in Controls) { c.Enabled = true; if (c is MenuStrip) { foreach(var item in ((MenuStrip)c).Items) { item.Enabled = true; } } if (c.ControlCollection.Count > 0) enableControls(c.Controls); } }

的修改

本来应该检查控件集合数,而不是HasControls哪家器WebControls

Should have been checking the control Collection count instead of HasControls Which is Webcontrols

更多推荐

如何使窗体上的所有控件?

本文发布于:2023-11-09 10:13:20,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1572102.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:窗体   控件

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!