自动重新生成设计器文件
最近,我对我们使用的许多控件进行了一些改进,例如为属性提供默认值以及将按钮设置为私有而不是受保护。 通过进行此类调整,您需要重新生成具有此控件的表单或从该控件继承的控件的设计器文件。
过去这并不是什么问题,因为我们只有 20-30 份表格。目前我们有超过 300 个表单,这意味着在 VS2010 中打开相同数量的设计器。
所以我的问题是:您知道一种自动化此过程以便重新生成所有表单的方法吗?
我一直在考虑一个宏来查找设计器文件并打开该文件(最多打开 25-50 个文件以确保 VS 不会崩溃),但我一直无法实现此功能。
我希望有人有建议!
Recently I've been making some improvements to a lot of the controls we use, for example give properties default values and making buttons private instead of protected.
By making this kind of adjustments you need to regenerate the designer files of the forms which have this control on it or controls which inherit from the control.
In the past this wasn't really a problem because we only had 20-30 forms. At the moment we've got more than 300 forms which would mean opening the same amount of designers in VS2010.
So my question: do you know a way of automating this process so all of the forms get regenerated?
I've been thinking about a macro which looks for designer files and opens the file (with a max of 25-50 files open to make sure VS won't crash), but I've not been able to get this working.
I hope someone has a suggestion!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我发现做你想做的事情的唯一方法是打开表单设计器,添加控件,然后保存。这将重新生成设计器代码。接下来删除新添加的控件,再次保存并关闭。
我通常通过双击工具箱中的按钮来添加按钮。这会将按钮置于位置 0,0。
几个月前,我在一个包含大约 100 个表单和用户控件的项目中完成了这项工作。我记录了一个临时宏,然后为每个表单/用户控件运行该宏并检查结果,而不是在项目文件上递归的宏。
不要将重构与重新格式化混淆。我经常以大型形式优化和/或修改设计器代码。例如,我将更改控件添加到面板的顺序,以及面板添加到其他面板的方式。 我不会盲目地重新生成设计器代码。
The only way I found to do what you want, is to open the form designer, add a control, then save. This will regenerate the designer code. Next delete the newly added control, save again, and close.
I usually add a button by double-clicking on the button in the toolbox. This puts the button at location 0,0.
I did this a couple months ago with a project with about 100 form and user-controls. Instead of a macro that recursed over the project files, I recorded a temporary macro then ran the macro for each form/user-control and inspected the results.
Do not confuse refactoring with reformatting. I often optimize and/or modify the designer code in large forms. For example, I will change the order controls are added to panels, and how panels are added to other panels. I would not blindly regenerate the designer code.
我也遇到了这个问题(另请参阅:强制 WinForms 重新生成 .designer.cs文件)。
最后,我删除的大多数属性都有唯一的名称,并且我能够编写一个 shell 脚本来从设计器文件中删除包含属性名称的行。
请注意,这实际上删除了该行,而不仅仅是留下一个空行。
它需要从 Bash Shell 运行,如果您安装了 msysgit,那么该 shell 就可以了。
在这个例子中,
TextForeColor
是被删除的属性。I also ran into this problem (see also: Force WinForms to regenerate .designer.cs files).
In the end, most of the properties I removed were uniquely named, and I was able to write a shell script to remove lines from the designer files that contained the property names.
Note, this actually removes the line, not just leaving a blank line.
It needs to be run from a Bash Shell, if you have msysgit installed, that shell is fine.
In this one,
TextForeColor
was the property being removed.使用表单的继承,而不是维护超过 300 个控件的更改。
Employ form's inheritance instead of maintaining changes over 300 controls.