如何自动调整窗口大小以适合其内容 [英] How to automatically size a Window to fit its content

查看:119
本文介绍了如何自动调整窗口大小以适合其内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用C#和Infragistics 15. 我有一个带有UltraGrid的WinForm,我想根据内容自动调整窗口的大小. 我寻找了这个,然后发现SizeToContent属性.

I'm using C# and Infragistics 15. I have a WinForm with an UltraGrid and I want to auto-ajust the window's size to the content. I looked for this and I found SizeToContent property.

但是我无法在窗口中找到此属性.

But I can not find this property with my window.

SizeToContent

FrmCVault是我窗口的名称.

FrmCVault is my window's name.

这是我一开始打开的窗口:

This is my windows when I open it at the beginning :

这是我向下滚动时的窗口,我想删除底部的空白以使其适合内容:

And this is my window when I scroll down, I'd like to delete the blank at the bottom, to make it fit to the content :

推荐答案

您可以将FormAutoSize属性设置为true,并将AutoSizeMode设置为GrowAndShrink.

You can Set AutoSize property of Form to true and Set AutoSizeMode to GrowAndShrink.

设计模式:

运行时间:

您还可以将此解决方案与FlowLayoutPanel混合,并将其AutoSize设置为true,将AutoSizeMode设置为GrownadShrink.

Also you can Mix this solution with a FlowLayoutPanel and set its AutoSize to true and AutoSizeMode to GrownadShrink.

如果您需要更紧密的设计,还可能需要设置控件PaddingMargin.

Also you may need to set controls Padding and Margin if you need more tight design.

根据您的编辑,答案现在有所不同,并且与UltraGrid控件有关.

Based on your edit, the answer is now a bit different and is related to UltraGrid control.

如果您的网格不支持自动调整大小,则可以使用上述说明,同时手动设置网格的高度yourGrid.Height = ((NumebrOfRows+1) * HeightOfRow),如果需要则添加其他空格.

If your grid doesn't support auto size, you can use described answer above, while you set the height of grid manually yourGrid.Height = ((NumebrOfRows+1) * HeightOfRow) and add additional spaces if you nedd.

这篇关于如何自动调整窗口大小以适合其内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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