c# - 以最小尺寸(仅显示标题栏)而不是与其属性设置的值对应的尺寸加载表单
问题描述
我有一个表单,其中包含一个Menu Strip
停靠在顶部、一个Status Strip
停靠在底部和一个Panel
停靠以填充上述控件之间的整个空间。我已将表单的属性设置为以下值:
在设计阶段:
AutoScaleMode: Dpi
AutoSize: false
AutoSizeMode: GrowOnly
DoubleBuffered: true
SizeGripStyle: Show
在运行时(在表单的构造函数中):
// Calculate the default size of the window on the basis of the ratio of the dimensions of the window to the dimension of the screen resolution of the machine used in development as the default dimensions of the window is aligned to that of the machine used to design it
this.Size = new Size(Screen.GetWorkingArea(this.Location).Size.Width * (widthOfWindowInDesignPhase /horizontalResolutionOfTheDisplayInDesignPhase), Screen.GetWorkingArea(this.Location).Size.Height * (heightOfWindowInDesignPhase / verticalResolutionOfTheDisplayInDesignPhase));
this.MinimumSize = new Size(this.Size.Width, this.Size.Height);
我第一次尝试解决这个问题是修改AutoSize
andAutoSizeMode
属性,但我需要将其设置为 aforestated 值,因为更改它们将不允许用户调整表单大小。我尝试的另一种方法也失败了,它是AutoSize
将上述控件的属性设置false
为强制窗体的子容器不调整大小。
提前致谢。
PS 相关表格截图:
解决方案
当计算表单的大小作为语句(widthOfWindowInDesignPhase /horizontalResolutionOfTheDisplayInDesignPhase)
并(heightOfWindowInDesignPhase / verticalResolutionOfTheDisplayInDesignPhase)
返回不能存储为整数的浮点值时,会发生(错误)数字错误。
适当的说法如下:
this.Size = new Size(Convert.ToInt32(Screen.GetWorkingArea(this.Location).Size.Width * (Convert.ToDouble(widthOfWindowInDesignPhase) / Convert.ToDouble(horizontalResolutionOfTheDisplayInDesignPhase))), Convert.ToInt32(Screen.GetWorkingArea(this.Location).Size.Height * (Convert.ToDouble(heightOfWindowInDesignPhase) / Convert.ToDouble(verticalResolutionOfTheDisplayInDesignPhase))));
推荐阅读
- android - 仅在数据更改时调用 LiveData.observe() 回调并忽略控制器的生命周期更改(活动/片段)
- javascript - 返回相反结果的子字符串
- ubuntu - 在使用 Ubuntu 18.04 的笔记本电脑上使用基于 libpcap 的软件
- javascript - 简化导入 - 性能受到影响?
- flutter - 从不同的有状态小部件更新值
- javascript - asp.net core 3 axios 没有按预期发布
- html - 文本换行在错误的位置
- docker - 跨机器时无法连接覆盖网络中的其他容器
- node.js - 如何在 typeorm 的自定义字段上做 orderBy?
- java - Kafka Producer 将消息发布到单个分区