一次使窗体上的所有控件为只读 [英] Make all Controls on a Form read-only at once
本文介绍了一次使窗体上的所有控件为只读的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有人有一段代码可以将所有控件(甚至所有文本框)制成一次性只读的表单,而不必将每个控件都设置为只读吗?
Does anyone have a piece of code to make all Controls (or even all TextBoxes) in a Form which is read-only at once without having to set every Control to read-only individually?
推荐答案
格式:
if (_cached == null)
{
_cached = new List<TextBox>();
foreach(var control in Controls)
{
TextBox textEdit = control as TextBox;
if (textEdit != null)
{
textEdit.ReadOnly = false;
_cached.Add(textEdit);
}
}
}
else
{
foreach(var control in _cached)
{
control .ReadOnly = false;
}
}
还添加递归(可以将控件放入其他控件中(面板)。
Add recursion also (Controls can be placed into other controls (panels)).
这篇关于一次使窗体上的所有控件为只读的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文