Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Resource files get modified when the form is opened in Visual Studio

When I open my main form design window (C# file in VS2010), the associated resource file gets automatically modified, sometimes it's location, sometimes it's the data for an image or just the order of the code gets rearranged. Everything still compiles and works fine, it's just annoying that I have to keep in mind to revert those changes or else I will constantly commit gibberish to my repository. Anybody know why this happens, perhaps because of some component?

EDIT:

For example, this data:

 <data name="connectToolStripMenuItem.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
    <value>
        somevalue
    </value>

Gets automatically changed to:

 <data name="connectToolStripMenuItem.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
    <value>
        someothervalue
    </value>

And put in a different spot. Everything still works fine, the problem is that those changes show up in my source control so I have to remember to revert the resx file before I do a commit, unless I actually do some modifications on the file, then I have to commit everything.

like image 398
Serge Avatar asked Apr 04 '11 19:04

Serge


1 Answers

unless I actually do some modifications on the file, then I have to commit everything

It is pretty unclear exactly what you do when you are forced to commit the .resx file to somehow not turn the image into "gibberish". The complaint just is not very credible, I'll assume that the real issue is that the .resx file changes and you have no idea why.

There is an increasingly common reason for .resx files to change without any obvious reason, just opening the form in the designer is enough. Especially so lately with Windows 10 getting more common. The underlying cause is the video adapter's DPI (dots-per-inch) setting. This setting has been stuck for decades at 100% (aka 96 dpi) but cheap very high resolution LCD panels are getting common, forcing users to increase the scaling to 125 or 150% to keep text legible. And for the Win10 installer to pick a higher value.

This has a pretty significant affect on the UI design, the Form.AutoScaleMode property does its job at design-time as well. Visual Studio is dpiAware so the designer can see the DPI change. WYSIWYG is preserved, as long as the app is declared dpiAware as well. Pretty important btw, finally made a little easier with VS2015 Update 1, the Application Manifest File item template now includes it. Just remove the comments.

This does change the .resx file content as well. Specifically for a MenuStrip, its TrayLocation is serialized to the file. And the menu item's OnImageScalingSizeChanged() method runs at design time. Also for any control if the form's Localizable property is set to True, that gets their Location and Size properties serialized to the .resx file.

The easiest way to recognize that is the underlying cause is to look at the form's Designer.cs file:

  this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F);

Compare this to the same property assignment on a brand new Winforms project. A different value is going to get the auto-rescaling to do its job and alter the .resx file.

Usual reason for a mismatch is a design that was created on another machine. Perhaps an older one. Or perhaps modified by another team member that runs his display adapter at a different DPI setting. Getting everybody to agree usually isn't that simple if team members don't have the same hardware. Giving everybody the same nice monitor is otherwise an excellent morale improvement for little money :) And perhaps you just shouldn't fight it that hard, just check it in so you won't have to be reminded next time.

like image 140
2 revs Avatar answered Oct 20 '22 09:10

2 revs