C#中 form窗体的宽度和高度最大值限制

C#中form窗体的宽度和高度最大值受制于屏幕分辨率,不能超过12像素。开发时需先获取屏幕分辨率以确保尺寸设置合理。示例代码展示了如何创建一个位于屏幕中央、透明度为75%且尺寸大于默认大小的窗体。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

C#中一个form的宽/高度的最大值,不能比它所运行的电脑上的屏幕的分辨率多于12 pixel 。所以程序中要先读取电脑的分辨率,再做判断。


csdn原文地址和从该地址拷贝的内容: 

https://msdn.microsoft.com/en-us/library/25w4thew.aspx

Form.Size Property

.NET Framework (current version)
 

Gets or sets the size of the form.

Namespace:    System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

Syntax

public Size Size { get; set; }
Property Value
Type:  System.Drawing.Size

Size that represents the size of the form.

Remarks

This property allows you to set both the height and width (in pixels) of the form at the same time instead of setting the Height and Width properties individually. If you want to set the size and location of a form, you can use the DesktopBounds property to size and locate the form based on desktop coordinates or use the Bounds property of the Control class to set the size and location of the form based on screen coordinates.

System_CAPS_noteNote

The maximum value of this property is limited by the resolution of the screen on which the form runs. The value cannot be greater than 12 pixels over each screen dimension (horizontal + 12 and vertical + 12).

System_CAPS_noteNote

On Pocket PC devices, you can create a resizable window by setting FormBorderStyle to Noneand removing any MainMenu control. On SmartPhone devices, you can never resize a Form - it will always fill the entire screen.

Examples

The following code example demonstrates how to create a form that is displayed with an opacity level of 75 percent. The example code creates a new form that is positioned in the center of the screen with an Opacity property set to change the opacity level of the form. The example code also sets the Size property to provide a larger sized form than the default size of the form. This example requires that the method defined in this example is called from another form in an event handler or other method.

private void CreateMyOpaqueForm()
{
   // Create a new form.
   Form form2 = new Form();
   // Set the text displayed in the caption.
   form2.Text = "My Form";
   // Set the opacity to 75%.
   form2.Opacity = .75;
   // Size the form to be 300 pixels in height and width.
   form2.Size = new Size(300,300);
   // Display the form in the center of the screen.
   form2.StartPosition = FormStartPosition.CenterScreen;

   // Display the form as a modal dialog box.
   form2.ShowDialog();
}

Version Information

.NET Framework
Available since 1.1

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值