[英]How to automatically size a Window to fit its content
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. 我正在使用C#和Infragistics15。我有一个带有UltraGrid的WinForm,我想根据内容自动调整窗口的大小。 I looked for this and I found SizeToContent property.
我寻找了这个,然后发现SizeToContent属性。
But I can not find this property with my window. 但是我在窗口中找不到此属性。
FrmCVault is my window's name. FrmCVault是我窗口的名称。
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 :
这是我向下滚动时的窗口,我想删除底部的空白以使其适合内容:
You can Set AutoSize
property of Form
to true and Set AutoSizeMode
to GrowAndShrink
. 您可以将
Form
AutoSize
属性设置为true,并将AutoSizeMode
设置为GrowAndShrink
。
Design Mode: 设计模式:
Run Time: 运行:
Also you can Mix this solution with a FlowLayoutPanel
and set its AutoSize
to true and AutoSizeMode
to GrownadShrink
. 您也可以将此解决方案与
FlowLayoutPanel
混合使用,并将其AutoSize
设置为true,将AutoSizeMode
为GrownadShrink
。
Also you may need to set controls Padding
and Margin
if you need more tight design. 另外,如果您需要更紧密的设计,则可能需要设置控件“
Padding
和“ Margin
。
Based on your edit, the answer is now a bit different and is related to UltraGrid control. 根据您的编辑,答案现在有所不同,并且与UltraGrid控件有关。
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. 如果您的网格不支持自动调整大小,则可以使用上面描述的答案,同时手动设置网格的高度
yourGrid.Height = ((NumebrOfRows+1) * HeightOfRow)
,如果需要则添加其他空格。
You need to set ScrollBounds of the grid to ScrollToFill. 您需要将网格的ScrollBounds设置为ScrollToFill。 You can use code like this:
您可以使用如下代码:
this.ultraGrid1.DisplayLayout.ScrollBounds = ScrollBounds.ScrollToFill;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.