Can I Tell Visual Studio not to Change the DPI of a Project?

前端 未结 2 1447
孤街浪徒
孤街浪徒 2020-12-30 12:42

I have a project converted from .NET 1.1 to 3.5 being developed in 2008.

If I open the project on Windows 7, it converts the size of everything to 120dpi sizes. If

相关标签:
2条回答
  • 2020-12-30 13:05

    AutoScaleMode = AutoScaleMode.None;

    See also: ContainerControl.AutoScaleMode property

    0 讨论(0)
  • 2020-12-30 13:30

    Since I ran into the same issue recently, I wanna share my workaround.

    First: KEEP AutoScaleMode = Font! This will work nicely at runtime to make your application DPI-aware. (Even cool per-Monitor DPI Aware).

    However, the WinForms Designer in Visual Studio actually evaluates the fonts sizes based on the system's DPI, and thus rescales whenever it thinks it is necessary. This is the core of the problem. This evaluation is triggered because the fonts usually specify their size in "point" (to give a DPI-independent user experience).

    My workaround is to change this for design time:

    • Set in your Forms Designer: Font = MS Sans; 11px. This is basically the OS default font, but specified with pixel-size. So no design-time rescaling will ever take place.
    • Now, to get High-DPI adaption back at runtime, change the Font back to use sizes specified in point. E.g. Font = SystemFonts.Default. A good place is in the Ctor right after InitializeComponents.

    I wrote the details about my workaround on my Blog: http://www.sgrottel.de/?p=1581&lang=en

    0 讨论(0)
提交回复
热议问题