简体   繁体   中英

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

在此处输入图片说明

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 :

在此处输入图片说明

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.

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM