给Windows窗体控件一个百分比宽度/高度 [英] Give Windows Form control a percentage width/height

查看:37
本文介绍了给Windows窗体控件一个百分比宽度/高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Windows Form开发的新知识,但是在Web开发方面经验丰富.有没有一种方法可以给Windows窗体控件分配一个百分比宽度/高度,以便在用户调整窗口大小时它可以展开/收缩?可以在窗口调整大小时编写代码来更改控件的宽度/高度,但是我希望有一种更好的方法,例如HTML/CSS.有吗?

Kind of new to Windows Form development, but well-experienced in web development. Is there a way to assign a percentage width/height to a Windows Form control so that it expands/shrinks as the user resizes the window? It would be possible to write code to alter the width/height of the control as the window resizes, but I'm hoping there's a better way like in HTML/CSS. Is there?

推荐答案

总之,没有.不过,您可以在Parent控件调整大小事件中以编程方式轻松地完成此操作.例如:

In a word, no. You can easily do it programmatically in the Parent control resize event though. For example:

    private void Form1_Resize(object sender, EventArgs e)
    {
        dataGridView1.Width = Convert.ToInt32(this.Width * 0.9);
        dataGridView1.Height = Convert.ToInt32(this.Height * 0.9);
    }

但是,如果可以的话,请使用上面评论中提到的WPF.

But if you can, use WPF as mentioned in the comments above.

这篇关于给Windows窗体控件一个百分比宽度/高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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