我需要设置表单上每个文本框的高度,其中一些文本框嵌套在其他控件中.我以为我可以这样做:
private static IEnumerator<TextBox> FindTextBoxes(Control rootControl)
{
foreach (Control control in rootControl.Controls)
{
if (control.Controls.Count > 0)
{
// Recursively search for any TextBoxes within each child control
foreach (TextBox textBox in FindTextBoxes(control))
{
yield return textBox;
}
}
TextBox textBox2 = control as TextBox;
if (textBox2 != null)
{
yield return textBox2;
}
}
}
Run Code Online (Sandbox Code Playgroud)
像这样使用它:
foreach(TextBox textBox in FindTextBoxes(this))
{
textBox.Height = height;
}
Run Code Online (Sandbox Code Playgroud)
但是编译器当然会吐出它的假,因为foreach期望IEnumerable而不是IEnumerator.
有没有办法在不必使用GetEnumerator()方法创建单独的类的情况下执行此操作?
我一直在用
Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
现在可以获得用户桌面的路径,但是由于我们在工作中更改了设置,因此我们使用文件夹重定向将用户的桌面和我的文档文件夹映射到服务器,它不再有效.它仍然指向C:\ Documents and Settings中的Desktop文件夹,这不是我的桌面所在的位置.
有想法该怎么解决这个吗?
伯恩斯