I have a simple drag-n-drop image viewer. It is setup as follows
- I have my main form
- I create a panel and stretch it to the size of the form,
autoscroll= true - I dock a picture box in the panel,
sizemode= autosize
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 1024×768, 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.
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.