MxLDevs
MxLDevs

Reputation: 19506

C# Setting the MaximumSize of a control to the parent's current size

I have a simple drag-n-drop image viewer. It is setup as follows

I drag a picture onto the picture box it loads the image. The picture box resizes to the image's dimensions, and my panel displays scrollbars as needed.

Now I maximize the form...But the panel doesn't get resized.

So I dock the panel in the main form, and now I maximize the form and the panel resizes.

Except now the scrollbars are gone. I am guessing the problem is that the panel was allowed to resize to however big it needed, so the scrollbars were no longer needed.

I hardcode the MaximumSize field for the panel to something like 1024x768, and the panel resized itself to that size and then displayed scroll bars as needed since the image is larger.

But everyone's resolutions are different, so how can I set the MaximumSize of the panel to that of its parent's current size? The parent can be another panel or form, though not in my specific case.

Upvotes: 0

Views: 3480

Answers (2)

HerrFlockig
HerrFlockig

Reputation: 63

Forms have a property called Size, which contains the the Height and Width of the form in pixels. You can use that to set the Size of your control. I'd suggest putting that code in the OnResize event handler so the control gets resized every time the form is.

Upvotes: 1

HatSoft
HatSoft

Reputation: 11191

To resize controls dynamically with the form, you can use the Anchor property of Windows Forms controls.

My suggestion would be you use along with Docking property also these properties can be set from the designer

Upvotes: 1

Related Questions