N0xus
N0xus

Reputation: 2724

Winform auto size to picture box

I'm wanting my winform to conform to the size of an image I pass to an image box held on my form. When I start the program it looks like this: enter image description here

Then when I pass an image to my picture box it reshapes to this: enter image description here

However, what I actually want is for the winform to resemble this. I had to manually drag the window to get it this way: enter image description here

I'm not entirely sure how I can achieve the third one via code. At the moment this is what i have:

this.Size = new Size(imagePreview.Width, imagePreview.Height);

Is there something else I can do code wise so i always end up with the result in the third picture, no matter what size of the image?

Upvotes: 1

Views: 2025

Answers (1)

user2704193
user2704193

Reputation:

There is one built-in property that could help you - Size Mode. Try it and if this does not suit your needs you can implement your own method for this - click me!

Upvotes: 1

Related Questions