views:

300

answers:

1

I have a picturebox where I change the BackgroundImage frequently. I have a the BackgroundImageLayout set to Zoom.

The problem is that when an image does not have the same scale as the picturebox, the picture is drawn in the middle. That is, the top and the bottom padding of the picturebox is always the same.

I would like for the BackgroundImage to always be aligned at the top. What is the easiest and most performance efficient way of doing this?

I can add that I download the images from the internet. If you think that the best way to deal with this is to resize them at that point I can do that :)

+1  A: 

By far the simplest solution is to just change the Size property of the picture box so that the image can be drawn without padding. Implementing your own Paint event handler is possible too, not exactly necessary here I presume.

Hans Passant
@Hans Thanks, worked perfectly :) But isn't this very slow?
Oskar Kjellin
Changing the size causes a Paint event. Not an issue, setting the BackgroundImage property does as well. Do it at the same time and you'll get only one.
Hans Passant