0

I want to display the image files from any given folder in a WebBrowser object.

Ideally I'd like it so that if an image is narrower than the WebBrowser object it is displayed at its original size, but if an image is wider than the WebBrowser object it automatically resizes (maintaining the aspect ratio) to the width of the WebBrowser object. I want to avoid having to scroll horizontally, in other words.

Can I do this using styles?

Andy Groom
  • 619
  • 1
  • 7
  • 15

1 Answers1

0

Set width to 100% and max-width to the width of the original image in pixels.

#myImage {
   width:100%;
   max-width:250px;
}

See How to inject CSS in WebBrowser control? for using CSS with WebBrowser.

Community
  • 1
  • 1
Qaz
  • 1,556
  • 2
  • 20
  • 34
  • Is there a way to do it without knowing the width of the image? ie. the browser figures out whether it's too wide to fit and reduces it? – Andy Groom Jun 25 '14 at 15:56
  • Width:100% reduces it if it's too wide for the container. The trouble is that it also stretches it if it's too small. HTML/CSS don't have a way I know of for the browser to know the original size of the image, but you might find something in JS/jQuery. – Qaz Jun 25 '14 at 15:59