Table of contents
(1) Open the Registry Editor (WIN+R key combination, enter regedit)
1. Problems
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.
- You don't want to change the display settings back to 100%, since scaling is set there must be a reason;
- You want to set VS separately to 100% zoom, but Windows 10 does not seem to have this setting option;
- 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
- First, the easiest solution: every time VS displays this information bar, click the "Restart Visual Studio with 100% scaling" option;
- Helpless solution: Change the Win10 zoom setting back to 100% (strange, why do I say this solution.. Crossed out);
- The best solution: set the Visual Studio software to ignore the DPI display scaling of Windows 10;
3. The best solution
- 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)
(2) Navigation
计算机\HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers
(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 )
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
After filling it out, it looks like this: (Note that the data value in the picture is missing an 'E')
(6) Verification result
Close all VS windows;
Restart VS, and open a form designer;
Four. Summary
- 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;
- 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;
- ① The problem in point 2 only affects the VS software, and it does not affect you at all when you use other software;
- ②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;
- ③In addition, you can also click the "Restart Visual Studio with automatic scaling" option;
- If you encounter similar problems when using other software , you can solve them through this problem;
- 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