C# Winfrom项目中,有个webBrowser控件,大小为:900*540。webBrowser控件中内嵌的网页大小为:1000*600。
怎么样让网页的整体内容缩小到90%后再嵌入到webBrowser控件中显示呢?
请问,能不能提供相关的源码或参考资料。谢谢!
this.webBrowser1.Document.Body.Style = "zoom:1.0";
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Myfirstprogram
{
public partial class Client : Form
{
public Client()
{
InitializeComponent();
this.Load += new EventHandler(Client_Load);
webBrowser1.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(webBrowser1_DocumentCompleted);
}
private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
if (webBrowser1.ReadyState != WebBrowserReadyState.Complete) return;
Size szb = new Size(webBrowser1.Document.Body.OffsetRectangle.Width,
webBrowser1.Document.Body.OffsetRectangle.Height);
Size sz = webBrowser1.Size;
int xbili = (int)((float)sz.Width / (float)szb.Width * 100);//水平方向缩小比例
int ybili = (int)((float)sz.Height / (float)szb.Height * 100);//垂直方向缩小比例
if(xbili<ybili)
webBrowser1.Document.Body.Style = "zoom:" + xbili.ToString() + "%";
else
webBrowser1.Document.Body.Style = "zoom:" + ybili.ToString() + "%";
webBrowser1.Invalidate();
}
private void Client_Load(object sender, EventArgs e)
{
webBrowser1.Navigate("http://www.csdn.net/");
webBrowser1.ScriptErrorsSuppressed = false;
webBrowser1.ScrollBarsEnabled = false;
}
}
}
这样还不行,有滚动条。这样让它整体通过缩放百分比的方式显示在webBrowser控件中呢?