繁体   English   中英

C#Web浏览器内容调整大小

[英]C# Web Browser content resize

我有一个C#应用程序,内部有一个WebBrowser,该应用程序提取了被认为是来自论坛的图像的html链接,然后我告诉WebBrowser导航到该图像链接以逐个显示图像。

问题是这些图像中的一些比我的WebBrowser对象的大小大得多。 我不想调整窗口大小,我喜欢它的大小是:)

我想调整Web浏览器页面的大小,例如,当您打开图像链接而没有最大化它们时,例如firefox和chrome这样做,它们只是缩小了以适合窗口大小?

提前致谢

解决方案:很好,Elerium(Top Answer)提供了链接,只是将VB代码更改为C#

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 > 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());
}

看起来像你要找的答案。 这里

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM