表单调整大小时如何调整datagridview控件的大小 [英] How to resize datagridview control when form resizes
问题描述
我发现了很多有关在调整子控件大小时如何调整表单大小的问题,但是我试图做一些更简单的事情(也许如此简单的人甚至不问它:|)
I found a lot of questions about how to resize the form when a child control resizes, but I'm trying to do something much simpler (maybe so simple people don't even ask it :| )
我想自动调整datagridview的宽度大小以填充表单的宽度。简单地将datagridview放置在表单上之后,调整表单大小时,网格将保持相同的大小。即使当我使用小的恒定距离捕捉功能将控件连接到窗体的边框时,也会发生这种情况。
I'd like to automatically resize my datagridview's width to fill the width of the form. After simply placing the datagridview on the form, the grid stays the same size when the form is resized. That happens even when I use the little constant-distance-snap thing 'connecting' the control to the form's borders.
我是否必须处理form.resize事件,
Do I have to handle a form.resize event of some sorts, or is there a property I can set in VS?
推荐答案
使用控件锚定。将 GridView
的属性 Anchor
设置为顶部,左侧,右侧
,它将随容器调整大小。如果将 GridView
放在某个容器内(例如 Panel
),则 Panel
也应该锚定。
Use control anchoring. Set property Anchor
of your GridView
to Top, Left, Right
and it will resize with container. If your GridView
are placed inside of some container (ex Panel
) then Panel
should be anchored too.
这篇关于表单调整大小时如何调整datagridview控件的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!