- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在我的桌面上,我的默认显示比例因子为 100%。当我创建一个表单大小为 400x200 且具有 3 个大小为 75x23 的图片框的简单应用程序时,它会按预期显示(图 1)。
当我在显示比例为 125% 的笔记本电脑上运行该程序时,它没有按预期显示(图 2)。
表格不合比例。现在是 530x244,宽度是 1.33x400,高度是 1.22x200。
红色的图片框也是不合比例的,是100x28。横向尺寸为1.33x75,纵向尺寸为1.25x23。
绿色和蓝色图片框的大小在代码中设置。
public Form1()
{
InitializeComponent();
double factor = CreateGraphics().DpiX / 96f;
pictureBox2.Size = new Size((int)(75 * factor), (int)(23 * factor));
pictureBox3.Size = new Size(75, 23);
label1.Text = String.Format("Form:{0}-{1} DpiX:{2} DpiY:{3}",
this.Size.Width,
this.Size.Height,
CreateGraphics().DpiX,
CreateGraphics().DpiY
);
label2.Text = String.Format("{0}-{1}", pictureBox1.Size.Width, pictureBox1.Size.Height);
label3.Text = String.Format("{0}-{1}", pictureBox2.Size.Width, pictureBox2.Size.Height);
label4.Text = String.Format("{0}-{1}", pictureBox3.Size.Width, pictureBox3.Size.Height);
}
窗体和图片框的初始大小在 InitializeComponent 函数中。
private void InitializeComponent()
{
this.label1 = new System.Windows.Forms.Label();
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.pictureBox2 = new System.Windows.Forms.PictureBox();
this.pictureBox3 = new System.Windows.Forms.PictureBox();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.label4 = new System.Windows.Forms.Label();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.pictureBox2)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.pictureBox3)).BeginInit();
this.SuspendLayout();
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(12, 9);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(35, 13);
this.label1.TabIndex = 0;
this.label1.Text = "label1";
//
// pictureBox1
//
this.pictureBox1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(192)))), ((int)(((byte)(192)))));
this.pictureBox1.Location = new System.Drawing.Point(14, 32);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(75, 23);
this.pictureBox1.TabIndex = 8;
this.pictureBox1.TabStop = false;
//
// pictureBox2
//
this.pictureBox2.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(192)))), ((int)(((byte)(255)))), ((int)(((byte)(192)))));
this.pictureBox2.Location = new System.Drawing.Point(14, 61);
this.pictureBox2.Name = "pictureBox2";
this.pictureBox2.Size = new System.Drawing.Size(75, 23);
this.pictureBox2.TabIndex = 11;
this.pictureBox2.TabStop = false;
//
// pictureBox3
//
this.pictureBox3.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(192)))), ((int)(((byte)(255)))), ((int)(((byte)(255)))));
this.pictureBox3.Location = new System.Drawing.Point(14, 90);
this.pictureBox3.Name = "pictureBox3";
this.pictureBox3.Size = new System.Drawing.Size(75, 23);
this.pictureBox3.TabIndex = 15;
this.pictureBox3.TabStop = false;
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(96, 41);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(35, 13);
this.label2.TabIndex = 16;
this.label2.Text = "label2";
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(96, 71);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(35, 13);
this.label3.TabIndex = 17;
this.label3.Text = "label3";
//
// label4
//
this.label4.AutoSize = true;
this.label4.Location = new System.Drawing.Point(96, 100);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(35, 13);
this.label4.TabIndex = 18;
this.label4.Text = "label4";
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.AutoScroll = true;
this.ClientSize = new System.Drawing.Size(384, 162);
this.Controls.Add(this.label4);
this.Controls.Add(this.label3);
this.Controls.Add(this.label2);
this.Controls.Add(this.pictureBox3);
this.Controls.Add(this.pictureBox2);
this.Controls.Add(this.pictureBox1);
this.Controls.Add(this.label1);
this.Name = "Form1";
this.Text = "Form1";
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.pictureBox2)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.pictureBox3)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Label label1;
private System.Windows.Forms.PictureBox pictureBox1;
private System.Windows.Forms.PictureBox pictureBox2;
private System.Windows.Forms.PictureBox pictureBox3;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Label label4;
}
当缩放设置为 100% 时,DpiX 将为 96f。当设置为 125% 时,DpiX 将为 120f。绿色图片框使用因子进行缩放,大小为 93x28,符合预期(75*120/96=93 和 23*120/96=28)。作为引用,蓝色图片框显示了 75x23 的原始尺寸。
谁能帮我解释一下为什么表格和红色图片框不符合设计比例?因素1.33和1.22如何解释?
最佳答案
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
这是一个明智的选择。请注意 AutoScaleMode 属性的替代选择,您也可以选择 AutoScaleMode.Dpi。这是您希望会发生的事情。
但它没有,您为 Form 和 pictureBox1 获得的自动缩放是基于 AutoScaleMode.Font 的。很难看出,但如果仔细观察,您会注意到,您在第二张屏幕截图中没有得到相同的字体。默认设置是“Microsoft Sans Serif”,它在较新的 Windows 版本中已停用,您会得到一个替代品。应该是塞格。 Windows 中的部分机制使旧的 UI 设计在较新的操作系统版本上看起来焕然一新。请注意它的平均字符宽度要高得多。它弥补了这一点,这就是为什么你得到 1.33 而不是 1.25
你可以选择 AutoScaleMode.Dpi 然后你会得到你喜欢的数字。但冒着文本不再适合控件的风险。考虑使用在两台机器上都可用的字体(如 Tahoma)使其更易于预测。
您得到 1.22 是因为表单自动缩放其 ClientSize 属性,而不是 Size。边框大小相同,因此整体大小增加小于 1.25。如果用户修改他的主题以显示更大的标题文本和按钮,则可能会有更大的不同。只有 ClientSize 很重要,这是确保窗口内容适合的重要属性。
请注意您对 CreateGraphics() 的使用,它有太多的副作用。此方法只能通过首先创建 native 窗口来工作。这会导致自动缩放生效,比正常情况早得多。因此,您正在修改已经重新缩放的尺寸,这大大增加了困惑。此处更安全的版本是 Graphics.FromHwnd(IntPtr.Zero)
,现在您可以使用原始设计指标修改大小,至少在 Load 事件触发之前是这样。
关于winforms - 显示窗体和控件的缩放比例和大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42481619/
所以基本上我有一个导航栏,我只想有一定的宽度。它有 4 个元素,我希望它正好是这些元素的宽度。这是它在我的工作计算机上的样子。 这正是我想要的样子。导航栏在最后一个元素的末尾完美结束,并且居中。我自己
如何将多个过滤器链接到一个视频中? 基本上 - 我有一个叠加图像(透明 gif),想要将它居中,并为 gif 应用 30% 的不透明度。这就是我所拥有的: ffmpeg -i inputmovie.m
我正在使用此命令对视频进行编码 $transcode = FFMPEG_BINARY.' -loglevel panic -y -i "'.$files['original'].'" -vf scal
我正在使用 Laravel 网站,包括 照片滑动 . 这是我的问题:当我单击照片时,它会以预定义的高度和宽度(在我的情况下为 764X480)弹出。我希望我的照片以原始比例打开,而不是预定义的(因为我
假设我想计算每个组中不同值的比例。例如,使用 mtcars 数据,如何计算 am 的齿轮数量的相对频率(自动/手动)用 dplyr 一次性完成? library(dplyr) data(mtcars)
我用一个非常小的标记散点图数据点(见下面的屏幕截图)。当我使用非常小的标记 ',' 时,图例很难阅读(示例代码取自 here )。 (Python 3,Jupyter 实验室) 如何增加图例中标记的大
我有这个数据框: o d r kz p 1 3 1 5 NaN 1 3 2 0 NaN 1 10 1 7 NaN 1 10 3 1
我对 R 很陌生,所以如果我的问题中有不清楚的地方,请耐心等待。 我有一个 data.frame “蛋白质”有5列,即; 1.protein_name, 2.protein_FC, 3.protein
我有一个带有 webgl 的 Canvas 。我初始化 webgl,创建一个片段和一个顶点着色器、两个覆盖整体的三 Angular 形和一个纹理。 const vertexShaderSource =
我想找到包括旋转,比例和位置的匹配模板。但是cvMatchTemplate没有提供这些详细信息,它仅检测位置。 我看过使用棋盘的例子。但是我想用自定义图像实现相同的示例。 感谢帮助。 问候 最佳答案
我正在尝试制作像欧洲体育应用程序中那样的侧边栏菜单!当菜单从左侧滑动时,sourceviewcontroller 向左滑动并变小。 var percentWidthOfContainer = cont
https://stackblitz.com/edit/js-meta-viewport 在 Chrome 调试器中,当我点击“可以缩放”但无法在移动设备 (Nexus 5 (Chrome 70))
针对一台设备进行优化后, ImageView 会按照布局中定义的正确比例显示。然而,如何才能更进一步,使各种 ImageView 在不同设备上缩放? android:layout_width="fil
我正在尝试创建一个具有两个 View 的 View Controller ,其中一个实际上是自定义 TableView ,如下所示: 是否可以添加某种比例约束,以便在所有设备和所有方向上,上 View
我正在使用 PhoneGap 为 Android 开发。下面你可以看到我的代码,我不能做的是在用户更改比例后将 WebView 比例重置为 1。 The reset code should be im
我有一个涉及大量图像的元素。 问题是每个图像都有不同的分辨率(高度/宽度)。它从 200x600 之类的小图像变成了 3000x5000 大声笑。 我正在尝试找到一种方法将所有图像的大小减小到 (MA
我想在运行时设置视口(viewport)比例 - 移动浏览器是否应该在设置后立即应用更改?这就是我正在尝试的: var scale = 2.0; var viewport = document.get
我在 paperjs 中有一个圆形和一个矩形对象。现在我想制作动画。在该动画中,圆圈上升并且矩形必须在圆圈之后(在圆圈底部)增长。我在这里有一个例子(不是我想要的那样工作) example 代码: v
对不起,我不能给标题带来完美的含义。您可以在 http://dainielhhong.com/page1.html 测试代码 无论屏幕大小如何,我都想使 crack 和 box fit。 它适合我的显
我是 D3 v3 的新手,正在学习一些有关基本线性和序数尺度的教程。我正在修改教程中的一段代码。我想让颜色根据窗口的大小显示和缩放。如果有更多数据,那么它应该再次均匀分布以容纳所有数据。 var da
我是一名优秀的程序员,十分优秀!