在C#中运行时更改表单大小 [英] Change form size at runtime in C#

查看:59
本文介绍了在C#中运行时更改表单大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在运行时更改窗口表单的大小?

How can I change window form size at runtime?

我看到了一些示例,但是每个示例都需要Form.Size属性.可以在此处设置此属性: http://msdn.microsoft.com/en-us/library/25w4thew.aspx#Y456 ,但是我已经在可视工具中创建了应用程序表单,并且表单是这样创建的:

I saw examples, but every one requires Form.Size property. This property can be set like here: http://msdn.microsoft.com/en-us/library/25w4thew.aspx#Y456, but I've created my application form in a visual tool and the form is created like this:

static void Main()
{
    Application.Run(new Form());
}

现在如何设置 Size 属性,然后通过 Form.Height Form.Width 方法进行更改?

How do I set that Size property now and then change it by the Form.Height and Form.Width methods?

推荐答案

如果要以编程方式处理表单,最简单的解决方案是保留对该表单的引用:

If you want to manipulate the form programmatically the simplest solution is to keep a reference to it:

static Form myForm;

static void Main()
{
    myForm = new Form();
    Application.Run(myForm);
}

然后,您可以使用它在运行时更改大小(或其他任何您想做的事情).尽管箭头指出,但是您无法设置 Width Height 直接,但必须设置 Size 属性.

You can then use that to change the size (or what ever else you want to do) at run time. Though as Arrow points out you can't set the Width and Height directly but have to set the Size property.

这篇关于在C#中运行时更改表单大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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