问题
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