Form1 视觉尺寸与 Form1 调试视觉尺寸不匹配 [英] Form1 visual size doesn't match Form1 debug visual size

查看:30
本文介绍了Form1 视觉尺寸与 Form1 调试视觉尺寸不匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到一个问题,当我调试我的应用程序时,它与我在设计器中设置的大小不匹配.我已经尝试将表单最小尺寸设置为所需的值.

I'm having a problem that when i debug my application it doesn't match the size i've set in the designer. i've tried to set form minimum size to the desirable values.

该表单由一个拆分面板构成,每边都有一个面板作为填充停靠.标签具有默认锚点.文本框有左、上、右锚点.按钮左上角有锚点.

The form is built up with a splitpanel, with a panel docked as fill on each side. The labels have default anchors. Textboxes have anchors left,top,right. Buttons have anchors left, top.

如果我在运行时向下拖动底部,我会得到我想要的尺寸/设计,但为什么它不是这样开始的,我该如何解决?

if i drag the bottom down during runtime i get the size/design i want, but why doesn't it start like that and how can i fix it?

推荐答案

看起来您正在处理高分辨率的屏幕.Windows 窗体在缩放内容方面不是很好,并且具有您需要注意的各种怪癖.如果可能,我会转向 WPF,但如果您确实需要继续使用 Windows 窗体,那么您应该这样做.

Looks like you're working on quite a high resolution screen. Windows Forms isn't very good with scaling the content and has all kinds of quirks that you need to be aware of. I would move to WPF if possible, but if you really need to continue using Windows Forms, here's what you should do.

  • 使用 AutoScaleMode.Dpi 在您的主窗体上.当显示器的 DPI 高于默认值 96 (100%) 时,它将缩放和重新定位控件以匹配您的设计.您也可以尝试 AutoScaleMode.Font,但如果您使用默认字体(Tahoma 8,25 pt 或类似字体)以外的字体,它可能无法正常工作.
  • 使用 TableLayoutPanelFlowLayoutPanel 使定位控件更容易.FlowLayoutPanel 动态地水平或垂直放置您的控件.如果您熟悉 WPF 或 Windows Phone 开发,它基本上是一个 StackPanel 控件.
  • 确保您的屏幕 DPI 为 96 (100%) 并在整个开发过程中保持相同.您仍然需要确保在其他 DPI 上测试应用程序,以便具有不同设置的用户能够使用您的应用程序.
  • Use AutoScaleMode.Dpi on your main form. It'll scale and relocate the controls to match your design when the DPI of the monitor is higher than the default 96 (100%). You could also try AutoScaleMode.Font but it might not work well if you use fonts other than the default (Tahoma 8,25 pt or something like that).
  • Use TableLayoutPanel or FlowLayoutPanel to make positioning controls easier. FlowLayoutPanel dynamically lays down your controls horizontally or vertically. If you're familiar with WPF or Windows Phone development, it's basically a StackPanel control.
  • Make sure your screen DPI is 96 (100%) and keep it the same throughout the development. You'll still have to make sure to test the application on other DPI's so that users with different settings will be able to use your application.

以下是有关 DPI 缩放的更多信息:

Here's more information about DPI scaling:

编辑:Visual Studio 的 Windows 窗体设计器使用与 Windows 版本不同的主题来显示窗体,因此这就是窗体在运行时看起来不同的原因之一.在运行时,表单使用当前运行应用程序的操作系统的主题.

Visual Studio's Windows Forms designer shows the form using a different theme than your Windows version so that's one reason why your form looks different in runtime. In runtime the form uses the theme of the operating system currently running the application.

这篇关于Form1 视觉尺寸与 Form1 调试视觉尺寸不匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆