Lets say I have multiple DataGrids throughout my winform app and I want to set the BackColor on ALL of them to Purple in Visual Studio.
假设我的winform应用程序中有多个DataGrids,我想在Visual Studio中将所有这些DataCr设置为Purple。
What is the fastest way of setting a Property for multiple items NOT located on the same Form?
为不在同一表单上的多个项目设置属性的最快方法是什么?
Thanks!
谢谢!
3 个解决方案
#1
2
Since you're asking about changing this at design time and not runtime, I would do a search on your whole solution for "new DataGrid" and change them in the designer.cs (or designer.vb) files. Other than that, I can't think of a quicker way other than maybe writing some sort of macro.
既然你要求在设计时而不是运行时更改它,我会在整个解决方案中搜索“new DataGrid”并在designer.cs(或designer.vb)文件中进行更改。除此之外,除了编写某种宏之外,我想不出更快的方法。
#2
2
There is an Application.OpenForms
property - you can loop over that list, then loop over the Controls property of each control recursively, modding those that match your type.
有一个Application.OpenForms属性 - 你可以遍历该列表,然后递归遍历每个控件的Controls属性,修改那些匹配你的类型。
Is that the kind of thing you're looking for?
那是你要找的那种东西吗?
#3
1
Rather than search for "new DataGrid", why not search for ".BackColor =" which is the line you'll be changing (keeping in mind that other controls have a .BackColor property so don't just do a blind update).
而不是搜索“new DataGrid”,为什么不搜索“.BackColor =”这是你将要改变的行(请记住,其他控件具有.BackColor属性,所以不要只是盲目更新)。
Hope this helps,
希望这可以帮助,
Bill
法案
#1
2
Since you're asking about changing this at design time and not runtime, I would do a search on your whole solution for "new DataGrid" and change them in the designer.cs (or designer.vb) files. Other than that, I can't think of a quicker way other than maybe writing some sort of macro.
既然你要求在设计时而不是运行时更改它,我会在整个解决方案中搜索“new DataGrid”并在designer.cs(或designer.vb)文件中进行更改。除此之外,除了编写某种宏之外,我想不出更快的方法。
#2
2
There is an Application.OpenForms
property - you can loop over that list, then loop over the Controls property of each control recursively, modding those that match your type.
有一个Application.OpenForms属性 - 你可以遍历该列表,然后递归遍历每个控件的Controls属性,修改那些匹配你的类型。
Is that the kind of thing you're looking for?
那是你要找的那种东西吗?
#3
1
Rather than search for "new DataGrid", why not search for ".BackColor =" which is the line you'll be changing (keeping in mind that other controls have a .BackColor property so don't just do a blind update).
而不是搜索“new DataGrid”,为什么不搜索“.BackColor =”这是你将要改变的行(请记住,其他控件具有.BackColor属性,所以不要只是盲目更新)。
Hope this helps,
希望这可以帮助,
Bill
法案