我可以告诉 Visual Studio 不要更改项目的 DPI 吗?
我在 2008 年开发了一个从 .NET 1.1 转换为 3.5 的项目。
如果我在 Windows 7 上打开该项目,它会将所有内容的尺寸转换为 120dpi 尺寸。如果我随后以 96 dpi 打开它,它会变回来。有什么方法可以让我进行开发,使其在两者中看起来都不错,并且如果在具有不同 DPI 的系统上打开,Visual Studio 不会更改大小吗?
这个问题也许在这里更好地表达/重复: 视觉工作室设计器 dpi 设置
或者在这里: Visual Studio 和 DPI 问题
要明确的是,我想要做的是防止控件在设计器中调整大小。由具有不同 DPI 设置的多个开发人员使用。在我注意到此问题的所有情况下,我一直在使用升级为使用 Visual Studio 2008 的 .NET 1 或 .NET 2 项目,现在使用 Visual Studio 2010。
更新(以防万一)想与@Ben 竞争奖励积分):我有一个可以正确调整大小的表单,但窗口的大小会以编程方式更改。由于设计者不知道尺寸,因此如果使用不同 DPI 的开发人员触摸表单,窗口大小调整将不正确。除了在运行时不缩放 UI 之外,还有其他方法可以解决该问题吗?
例如:我为我的窗口声明了两种尺寸,如果开发人员在设计时使用 120 dpi,它们可以正常工作:
private static Size smallSize = new Size(960, 500);
private static Size largeSize = new Size(960, 615);
我只是想弄清楚我需要做什么,以免在有人编辑时出现可怕的设计回归96dpi 设计器中的表单。
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 I then open it with 96 dpi it changes back. Is there any way for me to develop so it looks good in both, and not have Visual Studio change the sizes if opened on a system with different DPI?
This question is perhaps better phrased/duplicated here:
visual studio designer dpi setting
Or here:
Visual Studio and DPI issue
To be clear what I am trying to do is prevent the control from being resized in the designer when being used by multiple developers with different DPI settings. In all cases where I've noticed this issue I've been working with a .NET 1 or .NET 2 project upgraded to use Visual Studio 2008 originally, now Visual Studio 2010.
Update (in case anyone wants to compete with @Ben for bonus points): I have a form which resizes correctly, but the size of the window gets changed programmatically. Because the designer isn't aware of the dimensions, the window resizes incorrectly if a developer using a different DPI touches the form. Is there a way of getting around that problem other than going back to not scaling the UI at runtime?
For instance: I have two sizes for my window declared, which work correctly if developers use 120 dpi at design time:
private static Size smallSize = new Size(960, 500);
private static Size largeSize = new Size(960, 615);
I'm just trying to wrap my head around what I would need to do to not have a horrible design regression if someone edits the form in a 96dpi designer.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
AutoScaleMode = AutoScaleMode.None;
请参阅另外:
ContainerControl.AutoScaleMode
属性AutoScaleMode = AutoScaleMode.None;
See also:
ContainerControl.AutoScaleMode
property由于我最近遇到了同样的问题,我想分享我的解决方法。
第一:保留
AutoScaleMode = Font
!这将在运行时很好地工作,使您的应用程序能够感知 DPI。 (甚至很酷的每个显示器 DPI Aware)。然而,Visual Studio 中的 WinForms Designer 实际上会根据系统的 DPI 来评估字体大小,因此在它认为有必要时会重新缩放。这是问题的核心。触发此评估是因为字体通常以“点”指定其大小(以提供独立于 DPI 的用户体验)。
我的解决方法是在设计时更改此设置:
Font = MS Sans; 11 像素。这基本上是操作系统默认字体,但用像素大小指定。因此,不会发生设计时重新调整。
Font = SystemFonts.Default
。一个好地方是在InitializeComponents
之后的 Ctor 中。我在我的博客上写了有关解决方法的详细信息:http://www.sgrottel。 de/?p=1581&lang=en
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:
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.Font = SystemFonts.Default
. A good place is in the Ctor right afterInitializeComponents
.I wrote the details about my workaround on my Blog: http://www.sgrottel.de/?p=1581&lang=en