Windows 10 display scaling causes Visual Studio 2017 WinForm form designer to interface/layout/size problems when designing under high DPI

Table of contents

 

1. Problems

Two, the solution

3. The best solution

(1) Open the Registry Editor (WIN+R key combination, enter regedit)

(2) Navigation

(3) Create a new string value

 (4) Fill in the value name (it is best to find the path of your own VS startup program and paste it in)

(5) Fill in the numerical data (note that it is complete, one less character and one more character will not work)

 (6) Verification result

Four. Summary


1. Problems

Figure 1 VS2017 and later versions of the form designer display problems
Figure 1 VS WinForm form designer display problem (the information bar was introduced in Visual Studio 2017 version 15.8)

You can see that when you open a WinForm form designer, a yellow message warning bar appears above the designer, then you must have set a non-100% DPI scaling (HDPI scaling) in the Windows 10 display settings, then you have designed a good The form interface of the system will have inconsistent characteristics such as size and layout at runtime, and even the problem of overlapping controls.

Win10 display scaling
Figure 2 Win10 display scaling settings
  1. You don't want to change the display settings back to 100%, since scaling is set there must be a reason;
  2. You want to set VS separately to 100% zoom, but Windows 10 does not seem to have this setting option;
  3. You often use the WinForm window designer, and you don’t want to open the project every time, click again, restart and so on a series of tedious operations (note: it must be the WinForm window designer, as for why, see the feasibility analysis below);

Two, the solution

  1. First, the easiest solution: every time VS displays this information bar, click the "Restart Visual Studio with 100% scaling" option;
  2. Helpless solution: Change the Win10 zoom setting back to 100% (strange, why do I say this solution.. Crossed out);
  3. The best solution: set the Visual Studio software to ignore the DPI display scaling of Windows 10;

3. The best solution

  1. feasibility

Solution 3 is feasible because Visual Studio itself supports Win10 DPI scaling, which is characterized by displaying the software at a normal size (enlarged) when displaying the software on a monitor with a resolution above 1K, such as 2K and 4K monitors;

However, the WinForm window designer of VS does not support automatic HDPI scaling, which is characterized by the fact that when designing a form, various forms, controls, and layouts are displayed in an unscaled state (the effect of a 1K resolution display); (For details, you can search for "DPI virtualization")

The overall effect of this is: (VS software is enlarged,) the WinForm form is not enlarged, and the compiled WinForm form program is enlarged again, so it looks larger than the designed form, and the control layout is different.

2. Operation steps

(1) Open the Registry Editor (WIN+R key combination, enter regedit)

Registry Editor
Figure 3 Open Registry Editor

(2) Navigation

计算机\HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers

(3) Create a new string value

new string value
Figure 4 New string value

 (4) Fill in the value name ( it is best to find the path of your own VS startup program and paste it in )

Depending on the version of Visual Studio you are using, use different values ​​(corresponding to change 2017/2019, C/D drive, etc.)

C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\devenv.exe

C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\devenv.exe

C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\devenv.exe

(5) Fill in the numerical data ( note that it is complete, one less character and one more character will not work )

DPIUNAWARE 

edit string
Figure 5 Edit string

After filling it out, it looks like this: (Note that the data value in the picture is missing an 'E')

registration form
Figure 6 Registry settings (note that the data value in the figure is missing an 'E')

 (6) Verification result

Close all VS windows;

Restart VS, and open a form designer;

process result
Figure 7 Operation result

Four. Summary

  1. It can be seen that this method is relatively simple and effective, and it must be much more convenient for you who often use VS to design forms;
  2. The disadvantage is that the software as a whole does not scale, then there will be problems with relatively small text, controls, etc. of the VS software when displayed on an HDPI (resolution greater than 1K) monitor, which will have a certain impact on operation and use;
  3. The problem in point 2 only affects the VS software, and it does not affect you at all when you use other software;
  4. ②And if you don't use the WinForm window designer much after finishing this project, then you can delete the registry string directly, even if you don't delete it, changing the character of a numerical data (as shown in Figure 6) Can make VS restore the scaling of Win10;
  5. ③In addition, you can also click the "Restart Visual Studio with automatic scaling" option;
  6. If you encounter similar problems when using other software , you can solve them through this problem;
  7. Of course, the real best solution should be to wait for Microsoft to adapt the WinForm form designer of Visual Studio to the automatic scaling function of Windows 10; after all, high-resolution displays have become widely popular now;

Personal experience, please correct me if there are any deficiencies!

For official documentation, please refer to: https://docs.microsoft.com/en-us/visualstudio/designers/disable-dpi-awareness?view=vs-2019#add-a-registry-entry

Guess you like

Origin blog.csdn.net/qq_27677599/article/details/103726587