[英]C# Web Browser content resize
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. 我有一个C#应用程序,内部有一个WebBrowser,该应用程序提取了被认为是来自论坛的图像的html链接,然后我告诉WebBrowser导航到该图像链接以逐个显示图像。
The problem is that some of these images are a lot larger than the size of my WebBrowser object. 问题是这些图像中的一些比我的WebBrowser对象的大小大得多。 I DO NOT WANT TO RESIZE THE WINDOW, I LIKE IT THE SIZE IT IS :)
我不想调整窗口大小,我喜欢它的大小是:)
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? 我想调整Web浏览器页面的大小,例如,当您打开图像链接而没有最大化它们时,例如firefox和chrome这样做,它们只是缩小了以适合窗口大小?
Thanks in advance 提前致谢
SOLUTION: Works a treat, Elerium(Top Answer) provided the link, just changed the VB code to C# 解决方案:很好,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.