[英]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.