我如何阅读Winform Height&动态宽度? [英] How Do I Read The Winform Height & Width Dynamically?

查看:57
本文介绍了我如何阅读Winform Height&动态宽度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想动态读取高度和宽度,而winform是相当大的。也就是说,在运行表单之后,可以通过更改表单大小来更改这些值。如果我使用

I want to dynamically read the height and width while winform is sizable. That is, after running the form the value of these can be changed with the change of form size. If I use

this.height or this.width

它只能读取初始值。

推荐答案

这很简单:)

It's simple :)
private void Form1_Resize(object sender, EventArgs e)
{
    label1.Text = this.Width + "," + this.Height;
}





-KR



-KR


不,高度和宽度属性反映了表格的当前大小。

要证明这一点,请在Load事件处理程序中添加标签和以下代码:

No, the Height and Width properties reflect the current size of the form.
To prove it, add a label, and the following code to your Load event handler:
private void Form1_Load(object sender, EventArgs e)
    {
    Timer t = new Timer();
    t.Interval = 100;
    t.Tick += new EventHandler(t_Tick);
    t.Start();
    }



然后添加处理程序:


Then add the handler:

void t_Tick(object sender, EventArgs e)
    {
    label1.Text = string.Format("{0}:{1}", Width, Height);
    }

运行您的应用,并在调整表单大小时查看标签。

Run your app, and look at the label while you resize the form.


这篇关于我如何阅读Winform Height&动态宽度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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