How to automatically size a Window to fit its content

青春壹個敷衍的年華 提交于 2020-02-25 06:31:13

问题


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 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 :


回答1:


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

Design Mode:

Run Time:

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

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

EDIT

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

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.




回答2:


You need to set ScrollBounds of the grid to ScrollToFill. You can use code like this:

this.ultraGrid1.DisplayLayout.ScrollBounds = ScrollBounds.ScrollToFill;


来源:https://stackoverflow.com/questions/32992558/how-to-automatically-size-a-window-to-fit-its-content

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!