Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Wednesday, March 1, 2017 1:50 AM
Hi, I've been using Visual Studio Community 2015 for a while with no problem. However, after switching to a new computer with higher resolution (3840x2160) a strange problem has occurred with my Visual C# Windows Forms Applications.
After migrating a solution to my new machine, everything built and ran fine. But when I resized a form in the designer, suddenly the size did not match after running. The sizes of the buttons, text boxes, and other components were fine, but the size of the whole window was not. Changing resolution to 1280x720 had no effect. The numbers in Form.Designer.cs do update appropriately.
I reproduced this with a new project, so I'm pretty sure none of the code from my old solution is involved here. The video is here: https://www.youtube.com/watch?v=2DIXGfymrqw&feature=youtu.be (I can't submit a link until my account is verified, but it doesn't tell me how to verify it, hmm...) Has anyone encountered this before? What can I do to fix it? Thanks.
All replies (6)
Thursday, March 2, 2017 5:07 AM | 1 vote
Hi Devon,
As the resolution in my side is not that high, for now I could not repro it in my side.
If I change the AutoSize to “True” in Form1 properties, I had the size issue, but “False” is fine (the resolution is 1600*900). It’s probably not the main reason to cause this issue in your side.
But, I found the AutoScaleMode, you could change it to Dpi to have a check.
Best regard,
Fletch
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
Thursday, March 2, 2017 12:50 PM | 2 votes
The Windows Forms designer has issues with high DPI displays.
The best approach is to configure the devenv.exe process to run in DPI-virtualization while designing forms, and in DPI-awareness while coding. This switch requires a manual change in the Registry and restart of VS. I am working on an extension to streamline the change.
Meantime use this:
Running Visual Studio or setups with DPI virtualization (DPI-unaware) on high DPI displays
and ensure that the designer uses always 6F, 13F:
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
My portal and blog about VSX: http://www.visualstudioextensibility.com<br/> Twitter: https://twitter.com/VSExtensibility\<br/> MZ-Tools productivity extension for Visual Studio: https://www.mztools.com
Sunday, March 5, 2017 2:59 AM
Thanks Fletch and Carlos for your replies, unfortunately changing the AutoScaleMode didn't fix the issue, and I can't find the registry that Carlos wants me to change. When I open regedit and go to visual studio, I can't find an entry for devenv.exe.
I also tried looking at the Designer.cs produced by my old machine (Win 8.1, 1366x768, Visual Studio Express 2013) and found the only difference was instead of lines like this
this.AutoScaleDimensions = new System.Drawing.SizeF(19F, 37F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(950, 925);
it produced a different scale, like
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(400, 400);
When I resize in the design view, the issue arises, but when I manually change the Designer.cs file such that the AutoScaleDimensions are (8,16), and scale down the size, the runtime size is at least closer to what it should be, though still imperfect. For the time being I will restore my old files and edit them without using the design view.
I opened a WPF project as well, just to try. It seemed to make windows with correct proportions, but too large by about 50%. I'm not about to transition my old projects to WPF, but maybe I will start new projects in WPF from now on if that supports high DPI better.
Sunday, March 5, 2017 10:50 AM
Hi Devon,
The registry entry for devenv.exe must be created, it doesn't exist by default.
My portal and blog about VSX: http://www.visualstudioextensibility.com<br/> Twitter: https://twitter.com/VSExtensibility\<br/> MZ-Tools productivity extension for Visual Studio: https://www.mztools.com
Wednesday, February 14, 2018 8:34 PM
Hey @Devon - Did you ever find a resolution to this?
I'm experiencing the same behaviour.
I've added the reg key suggested above and have added the below to the my form load events:
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
But still the forms don't display at runtime as they appear in the designer?
Any suggestions from anybody would be greatfully appreciated!
Thanks
Friday, December 6, 2019 6:57 PM
Did you find a solution?
I'm having the same problem right now