Note that there are some explanatory texts on larger screens.

plurals
  1. POC# Web Browser content resize
    primarykey
    data
    text
    <p>I've got a C# application, with a WebBrowser inside, the application pulls html links that are believed to be images from a forum and I then tell my WebBrowser to navigate to the image link to display the images one by one.</p> <p>The problem is that some of these images are a lot larger than the size of my WebBrowser object. I DO NOT WANT TO RESIZE THE WINDOW, I LIKE IT THE SIZE IT IS :)</p> <p>I want to get the webbrowser page to resize, for example like firefox and chrome do when you open an image link and you dont have them maximized, they just make it smaller to fit the window?</p> <p>Thanks in advance</p> <p>SOLUTION: Works a treat, Elerium(Top Answer) provided the link, just changed the VB code to C#</p> <pre><code>double origSizeWidth, origSizeHeight; origSizeWidth =webBrowser1.Size.Width; //get the original size of browser origSizeHeight = webBrowser1.Size.Height; HtmlElement pic = webBrowser1.Document.Images[0]; //get your image double origPicWidth, origPicHeight; origPicWidth = double.Parse(pic.GetAttribute("WIDTH")); //save the image width origPicHeight = double.Parse(pic.GetAttribute("HEIGHT"));//and height double tempW, tempY, widthScale, heightScale; double scale = 0; if(origPicWidth &gt; origSizeWidth){ widthScale = origSizeWidth / origPicWidth; //find out the scale factor for the width heightScale = origSizeHeight / origPicHeight; //scale factor for height scale = Math.Min(widthScale,heightScale);//determine which scale to use from the smallest tempW = origPicWidth * scale; //multiply picture original width by the scale tempY = origPicHeight * scale; // multiply original picture height by the scale pic.SetAttribute("WIDTH", tempW.ToString()); // set your attributes pic.SetAttribute("HEIGHT", tempY.ToString()); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload