在C#.NET中设置的最小窗口大小 [英] Set minimum window size in C# .NET

查看:268
本文介绍了在C#.NET中设置的最小窗口大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有麻烦我的设置窗口的最小尺寸在C#应用程序我的工作。我曾尝试code形式的构造函数:

I am having trouble setting the minimum size of my window in a C# application I am working on. I have tried this code in the form's constructor:

this.MinimumSize.Width = 800;
this.MinimumSize.Height = 600;

但是编译器说:

But the compiler says:

不能修改的返回值   'System.Windows.Forms.Control.MinimumSize,因为它不是一个变量

Cannot modify the return value of 'System.Windows.Forms.Control.MinimumSize' because it is not a variable

任何人都可以揭示出这个问题的一些光给我吗?

Can anybody shed some light on this issue for me?

编辑:

使用:

this.MinimumSize = new Size(800,600);

给出:

 error CS0118: 'System.Windows.Forms.Form.Size' is a 'property' but is used like a 'type'

对不起,我忘了提,我已经试过了。 也忘了提,我没有使用Visual Studio。

Sorry I forgot to mention that I had already tried that. Also forgot to mention that I am not using Visual Studio.

推荐答案

由于尺寸是一个结构,你不能这样做。
相反,你需要一个新的尺寸的值赋给属性,像这样的:

Since Size is a struct, you can't do that.
Instead, you need to assign a new Size value to the property, like this:

this.MinimumSize = new Size(800, 600);

修改您的编译器是错误的;它混淆了尺寸类与 Control.Size 属性。

EDIT Your compiler is wrong; it's confusing the Size class with the Control.Size property.

要解决这个不公正的错误,你需要限定的类型与命名空间:

To work around this unjust error, you need to qualify the type with a namespace:

this.MinimumSize = new System.Drawing.Size(800, 600);

或者你只是忘了使用System.Drawing中

这篇关于在C#.NET中设置的最小窗口大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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