日期:2014-05-19  浏览次数:20861 次

请教一个小问题:winform, 如何把页面中的所有textbox变成只读?
想寻找页面所有的文本框,然后把它们全部设置为只读。该怎么操作呢?

------解决方案--------------------
用鼠标选中所有文本框,然后在属性栏一次设ReadOnly 为 true ;
或者在表单Load事件中写代码控制。
private void Form1_Load(object sender, EventArgs e)
{
foreach (Control c in this.Controls)
{
if (c.GetType() == typeof(TextBox))
{
((TextBox)c).ReadOnly = true;
}
}
}
------解决方案--------------------
楼上正解!