表单加载时具有最小尺寸(仅显示标题栏),而不是与为其属性设置的值相对应的尺寸

问题描述 投票:0回答:1

我有一个表单,其中包含一个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);

我解决这个问题的第一个尝试是修改AutoSizeAutoSizeMode属性,但是我要求将此属性设置为预先确定的值,因为更改它们将不允许用户调整表单的大小。我尝试的另一种方法也失败了,方法是将上述控件的AutoSize属性设置为false,以强制不调整窗体的子容器大小。

提前感谢。

有关表格的PS屏幕截图:

Form loaded with the minimal size

c# .net windows winforms size
1个回答
0
投票

[由于语句(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))));

© www.soinside.com 2019 - 2024. All rights reserved.