首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

webbrowser控件 未将对象引用设立到对象的实例 坐等.

2012-10-12 
webbrowser控件未将对象引用设置到对象的实例坐等..using Systemusing System.Collections.Genericusing

webbrowser控件 未将对象引用设置到对象的实例 坐等..
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 C_sharp_KanCms_Banner_
{
  public partial class WebPage : Form
  {
  public WebPage()
  {
  InitializeComponent();
  this.webBrowser1.Navigate("www.baidu.com");
  this.webBrowser1.Document.Body.Style = "zoom:0.5";//出问题处 
  }
  }
}

[解决办法]
没有等DocumentComplete就访问Document……
[解决办法]
页面没可能立即就加载完成的。把
 this.webBrowser1.Document.Body.Style = "zoom:0.5";//出问题处

放到DocumentComplete事件中。

C# code
private void PrintHelpPage(){    // Create a WebBrowser instance.     WebBrowser webBrowserForPrinting = new WebBrowser();    // Add an event handler that prints the document after it loads.    webBrowserForPrinting.DocumentCompleted +=        new WebBrowserDocumentCompletedEventHandler(PrintDocument);    // Set the Url property to load the document.    webBrowserForPrinting.Url = new Uri(@"\\myshare\help.html");}private void PrintDocument(object sender,    WebBrowserDocumentCompletedEventArgs e){    // Print the document now that it is fully loaded.    ((WebBrowser)sender).Print();    // Dispose the WebBrowser now that the task is complete.     ((WebBrowser)sender).Dispose();} 

热点排行