自动表格尺寸 [英] Automatic form size

查看:127
本文介绍了自动表格尺寸的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的程序中,我创建了动态按钮.

解决方案

设置WidthHeight属性.


您需要跟踪4个值.

您的任何控件使用的最低Y值. (顶部)
您的任何控件使用的最高Y值. (底部)
您的任何控件使用的最低X值. (左)
您的任何控件使用的最高X值. (右)

然后,简单的总和将为您提供所需的宽度.添加您想要的任何图形作为边框(记住在两端分别乘以2).然后将Form的ClientSize设置为这些值.


使用Form1.AutoSize = true;默认值始终为false,它仅在运行时在设计器中不起作用.在我尝试过的情况下,它可以很好地工作,但是如果锚定所有控件等,它就可以做一些时髦的事情.

In my program I create dynamic buttons. How can I automatic resize the form that I can see all the buttons on the from?

解决方案

Set the Width and Height properties.


You need to keep track of 4 values.

The lowest Y value used by any of your controls. (Top)
The highest Y value used by any of your controls. (Bottom)
The lowest X value used by any of your controls. (Left)
The highest X value used by any of your controls. (Right)

Then a simple sum will give you the required width. Add whatever figure you want to have as a border (remember to multiply that by two for a border at each end). Then set the ClientSize of your Form to those values.


Use Form1.AutoSize = true; The default is always false and it won''t work in the designer, only at run time. It works fine for the cases I tried, but it does funky stuff if you anchor all your controls, etc.


这篇关于自动表格尺寸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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