本文介绍了如何避免在* .designer.cs和* .resx中进行不必要的更改?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于某些原因,Visual Studio winforms设计器有时会对表单设计器文件和相应的resx应用无聊的更改.

For some reason Visual Studio winforms designer time to time applies dull changes to form designer files and respective resx.

到目前为止,最烦人的是:

Most annoying so far:

  • 更改控件声明/初始化的顺序
  • 更改为某些控件大小(最显着的是菜单项的宽度)
  • 更改嵌入到资源中的序列化图像(...等等,什么?)

这些更改不会影响窗体/用户控件的功能或外观,但是它们会在源代码管理中产生大量干扰,几乎无法进行合并,或者需要易于出错的手动修复以消除所有实际更改的注意,直到设计师的下一个改变.

Those changes doesn't affect form/user control functionality or it look, but they create lot of noise in source control, making merges almost impossible, or require error prone manual fixing to eliminate all changes that actually change noting, just until next change to designer.

有什么主意如何防止录音室使用它吗?

Any ideas how to prevent studio from it?

推荐答案

请尝试使用右侧按钮锁定控件,然后在表单/用户控件"上选择锁定控件".

Please try to have your control locked using the right button, then select "Lock controls" on your Form/UserControl.

不幸的是,没有办法将生成的代码中的有用"更改与由控件设计者错误或内部工作引起的污染"分开.

Unfortunately, there is no way to separate "useful" changes in generated code from "pollution" that come from a control designer bug or internal working.

如果出于任何原因锁定控制功能无法正常工作,除了那些可怕的骇客之外,我们无能为力:

If the lock control feature does not work for whatever reasons, there is not much that we can do, except those horrible hacks:

  • 创建并完成表单后,将生成的代码(InitializeComponent方法和声明)移出.designer.cs. Visual Studio将不再对其进行触摸.缺点是您将不再获得视觉支持.

  • Once your form is created and finished, move your generated code (InitializeComponent method and declarations) out of the .designer.cs. Visual Studio will not touch it anymore. The drawback is that you will no longer have visual support.

将.designer.cs文件标记为只读将阻止Visual Studio尝试更改它.有时可能会导致Visual Studio控件设计者出现问题,但是会使您的.designer.cs保持完整.

Having the .designer.cs file flagged as read only will prevent Visual Studio attempting to change it. It might cause Visual Studio control designer hiccups sometimes, but it will leave your .designer.cs intact.

还有另一种方式,那就是完全不使用设计器.这将导致采用Winforms编程的新方法,因为您将提供用于初始化控件及其属性和事件的代码.

There is another way that consist in not using the designer at all. This leads to a new way to embrace winforms programming, because you will provide the code to initialize controls with their properties and events.

它并不像看起来那样庞大和丑陋:使用可重用的模式和OO功能可能非常令人愉快,并且某些对齐方式更好的方法调用比隐藏在.designer.cs文件中的可怕代码更好.

It is not as huge and ugly as it seems to be: using reusable patterns and OO features could be very pleasant, and some well aligned methods calls are better that some horrible code hidden in a .designer.cs file.

当然没有视觉上的支持,但是您可以通过在设计模式下将控件添加到空容器中来欺骗它,以查看其外观.

Of course there will be no visual support, but you can cheat it by adding your control to an empty container in design mode to see how it looks like.

这篇关于如何避免在* .designer.cs和* .resx中进行不必要的更改?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 23:36