简体   繁体   English

为Windows窗体控件提供百分比宽度/高度

[英]Give Windows Form control a percentage width/height

Kind of new to Windows Form development, but well-experienced in web development. Windows Form开发的新手,但在Web开发方面经验丰富。 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? 有没有办法为Windows窗体控件指定百分比宽度/高度,以便在用户调整窗口大小时扩展/缩小? 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. 当窗口调整大小时,可以编写代码来改变控件的宽度/高度,但我希望有更好的方法,比如在HTML / CSS中。 Is there? 在那儿?

In a word, no. 总之,没有。 You can easily do it programmatically in the Parent control resize event though. 您可以在Parent control resize事件中以编程方式轻松完成。 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);
    }

But if you can, use WPF as mentioned in the comments above. 但是,如果可以,请使用上面评论中提到的WPF。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM