你可以先在DW,FP中生成HTML代码,然后在Webbrowser中write出来

解决方案 »

  1.   

    可以这样试一试:
    1. 在HTML的head部分加上
    <META http-equiv=content-type content="text/html; charset=gb2312">
    2.点击右键”查看源代码(HTML的)",看看blank到底是从那儿来到。
      

  2.   

    remove the call to Document.Close()maybe you can call Document.Clear() before writing html
      

  3.   

    我碰到过, frame的src里面应该写src="about:blank"
    然后用msthml方式定位每个frame再往里面写内容.btw, frame是固定内容的话, 为什么不从资源里面载入呢?
      

  4.   

    写的乱了一点, 我的第一个.net程序
    private void Form1_Load(object sender, System.EventArgs e)
    {
    this.btnGo_Click(null,null);
    }
    public static String getPage(String url) 
    {
    WebResponse result = null;
    String r = ""; WebRequest req = WebRequest.Create(url);
    //Debug.WriteLine(req.Headers.Get("User-Agent"));
    //req.Headers.Add("User-Agent","Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.0.3705)");
    result = req.GetResponse();

    Stream ReceiveStream = result.GetResponseStream();
    Encoding encode = System.Text.Encoding.GetEncoding("utf-8");
    StreamReader sr = new StreamReader( ReceiveStream, encode );
    Console.WriteLine("\r\n已接收到响应流"); Char[] read = new Char[256];
    int count = sr.Read( read, 0, 256 );
    while (count > 0) 
    {
    String str = new String(read, 0, count);
    r += str;
    count = sr.Read(read, 0, 256);
    }
    if ( result != null ) 
    {
    result.Close();
    }
    return r;
    } private void btnGo_Click(object sender, System.EventArgs e)
    { String url;
    String t = System.DateTime.Now.ToLongTimeString();
    System.Console.WriteLine(t);
    url = textUrl.Text +"?"+t +this.textName.Text; System.Object nullObject = 0 ; 
    string str = "" ; 
    System.Object nullObjStr = str ; 
    Cursor.Current = Cursors.WaitCursor ; 
    axWebBrowser.Navigate ( url, ref nullObject , ref nullObjStr , ref nullObjStr , ref nullObjStr ) ; 
    Cursor.Current = Cursors.Default;

    } private void axWebBrowser_DocumentComplete(object sender, AxSHDocVw.DWebBrowserEvents2_DocumentCompleteEvent e)
    {
    Console.WriteLine("doc ok");
    } private void timer1_Tick(object sender, System.EventArgs e)
    {
    this.btnGo_Click(null,null) ;
    } private void button1_Click(object sender, System.EventArgs e)
    {
    this.timerLogin.Interval = int.Parse(this.textLoginInterval.Text)*1000;
    this.timerLogin.Enabled = ! this.timerLogin.Enabled;
    this.lblStatus.Text= this.timerLogin.Enabled.ToString();
    } private void btnFlush_Click(object sender, System.EventArgs e)
    {
    this.timerFlush.Interval = int.Parse(this.textFlushInterval.Text);
    this.timerFlush.Enabled = !this.timerFlush.Enabled;
    this.lblFlush.Text = this.timerFlush.Enabled.ToString();
    }
    private void doFlush()
    {
    mshtml.IHTMLDocument2 doc = (mshtml.IHTMLDocument2)this.axWebBrowser.Document;
    if (null==doc) 
    return;
    mshtml.IHTMLFramesCollection2 frms = (mshtml.IHTMLFramesCollection2)doc.frames;
    if(null==frms)
    return;
    System.Object obj = 4;
    object o = frms.item(ref obj);
    mshtml.IHTMLWindow2 win = (mshtml.IHTMLWindow2) o;/**
     *  for(int i=0;i<frms.length;i++)
    {
    Object ddd = i;
    mshtml.IHTMLWindow2 w = (mshtml.IHTMLWindow2) frms.item(ref ddd);
    Debug.WriteLine(""+i+w.location.href.ToString());
    }
    **/
    //if has login, userlist will be filled...
    obj = 3;
    object oList = frms.item(ref obj);
    mshtml.IHTMLWindow2 userlist = (mshtml.IHTMLWindow2) oList;
    Debug.WriteLine("userlist:"+userlist.document.all.length.ToString());
    if (userlist.document.all.length<10)
    return;

    //find pigs.
    if (this.checkFlushAllPigs.Checked)
    {
    System.Collections.ArrayList pigs = new System.Collections.ArrayList();

    object objTagA = "A";
    obj = 0;
    for (int i=15;i<100;i++)
    {
    obj = i;
    mshtml.IHTMLElement tagA = (mshtml.IHTMLElement)userlist.document.all.item(obj,obj);
    //Debug.WriteLineIf(tagA!=null,i+":"+tagA.tagName+":"+tagA.innerText);
    if (tagA!=null && tagA.tagName.Equals("A") &&tagA.innerText.StartsWith("@"))
    pigs.Add(tagA.innerText);
    }

    if (pigs.Count>0)
    {
    int index = new System.Random().Next(pigs.Count-1);
    this.textTo.Text = (String)pigs[index];
    }
    } obj = 1;
    // tagA = (mshtml.IHTMLElement)userlist.document.all.item(objTagA,obj);
    // Debug.WriteLine(tagA.innerText);
    object oForm = win.document.forms.item("submitform",null);
    mshtml.IHTMLFormElement form = (mshtml.IHTMLFormElement)oForm;

    mshtml.IHTMLInputElement msg = (mshtml.IHTMLInputElement)form.item("message",null);
    mshtml.IHTMLInputElement msg1 = (mshtml.IHTMLInputElement)form.item("message1",null);
    mshtml.IHTMLInputElement towho = (mshtml.IHTMLInputElement)form.item("towho",null);
    mshtml.IHTMLInputButtonElement submit = (mshtml.IHTMLInputButtonElement)form.item("submit",null);
    mshtml.IHTMLInputElement hid = (mshtml.IHTMLInputElement)form.item("hidd",null);

    if (this.checkPrivate.Checked)
    hid.@checked=true;

    msg1.value = this.textWords.Text;
    msg.value=msg1.value;
    if (towho.value == null || this.checkFlushAllPigs.Checked)
    towho.value=this.textTo.Text;
    form.submit();

    } private void axWebBrowser_DocumentComplete_1(object sender, AxSHDocVw.DWebBrowserEvents2_DocumentCompleteEvent e)
    {
    Debug.WriteLine(e.uRL.ToString());
    if (e.uRL.ToString().IndexOf("nph-irc")>0)
    this.btnGo_Click(null,null);
    } private void timerFlush_Tick(object sender, System.EventArgs e)
    {
    this.doFlush();
    }