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?
This class is contained in the Resources. Designer. cs file which is nested under the Resources. resx file in Solution Explorer. The Resources class encapsulates all your project resources into static readonly get properties as a way of providing strongly-typed resources at run-time.
Right click the resx-file and select properties. Add the value "PublicResXFileCodeGenerator" to the "Custom Tool" property then the designer file will be generated.
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:
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With