Search code examples
c#winformsinfragistics

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. I looked for this and I found SizeToContent property.

But I can not find this property with my window.

SizeToContent

enter image description here

FrmCVault is my window's name.

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

enter image description here 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 :

enter image description here


Solution

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

    Design Mode:

    enter image description here

    Run Time:

    enter image description here

    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.