Novellizator
Novellizator

Reputation: 14893

How to auto-adjust the size of a Form to fit the size of the controls?

let's say (for the sake of simplicity) that I have and event that when fired, calls

pictureBox1.Size = new Size(500, pictureBox1.Size.Height);

The problem is that although the control gets bigger, the main Form1 won't resize... (so I only see just a part of the control that is inside the main Form) (Note: dunno if important, but the picturebox is anchored)

I tried playing with the AutoSize and AutoSizeMode properties, but it didn't work. Can you give me a hand?

Upvotes: 0

Views: 2067

Answers (2)

Sina Iravanian
Sina Iravanian

Reputation: 16296

You must first disable the picture-box anchor, then resize the form (by changing its size properties I suppose), and then re-enable the anchors.

Or the better solution is that since the picture-box is anchored within the form, then you can only resize the form, and expect the anchor would result in the resizing of the picture-box as well.

Upvotes: 1

Rahul Tripathi
Rahul Tripathi

Reputation: 172588

You can use the Dock and Anchor properties

Upvotes: 0

Related Questions