问题描述
我做了一个窗体有两个按纽一个按纽用于在WebBrowser控件中显示URI的内容另一个用于在WebBrowser控件中显示该URI中的HTML代码这一个我搞不定急求解哪位大侠帮帮忙在线等呢
解决方案
解决方案二:
我也遇到過一個顯示word的在網上找的資料但出錯啊publicForm1(){InitializeComponent();this.axWebBrowser1.NavigateComplete2+=newAxSHDocVw.DWebBrowserEvents2_NavigateComplete2EventHandler(this.axWebBrowser1_NavigateComplete2);}privateobjectoDocument;privatevoidbutton1_Click(objectsender,EventArgse){StringstrFileName;//FindtheOfficedocument.openFileDialog1.FileName="";openFileDialog1.ShowDialog();strFileName=openFileDialog1.FileName;if(strFileName.Length!=0){Objectrefmissing=System.Reflection.Missing.Value;oDocument=null;axWebBrowser1.Navigate(strFileName,refrefmissing,refrefmissing,refrefmissing,refrefmissing);}}privatevoidForm1_Load(objectsender,EventArgse){button1.Text="Browse";openFileDialog1.Filter="OfficeDocuments(*.doc,*.xls,*.ppt)|*.doc;*.xls;*.ppt";openFileDialog1.FilterIndex=1;}publicvoidaxWebBrowser1_NavigateComplete2(objectsender,AxSHDocVw.DWebBrowserEvents2_NavigateComplete2Evente){//Note:Youcanusethereferencetothedocumentobjectto//automatethedocumentserver.Objecto=e.pDisp;oDocument=o.GetType().InvokeMember("Document",BindingFlags.GetProperty,null,o,null);ObjectoApplication=o.GetType().InvokeMember("Application",BindingFlags.GetProperty,null,oDocument,null);ObjectoName=o.GetType().InvokeMember("Name",BindingFlags.GetProperty,null,oApplication,null);MessageBox.Show("Fileopenedby:"+oName.ToString());}}
解决方案三:
Wb.Navigate("www.google.cn");HtmlDocumentdoc=Wb.Document;txtHtml.Text=doc.Body.InnerHtml;
解决方案四:
System.Net.WebRequestwrq=System.Net.WebRequest.Create(fileUrl);System.Net.WebResponsewrs=wrq.GetResponse();Streamstrm=wrs.GetResponseStream();StreamReadersr=newStreamReader(strm);MessageBox.Show(sr.ReadToEnd());
解决方案五:
各位大虾还是不行呢我要的是在WebBrowser控件中显示所指URI的的HTM代码呢
解决方案六:
usingSystem;usingSystem.IO;usingSystem.Net;classTest{//获取网页的HTML内容staticstringGetPage(stringurl){HttpWebRequestreq=(HttpWebRequest)WebRequest.Create(url);try{using(HttpWebResponseres=(HttpWebResponse)req.GetResponse()){using(StreamReadersr=newStreamReader(res.GetResponseStream())){returnsr.ReadToEnd();}}}catch(System.Exceptione){returne.Message;}finally{req.Abort();}}staticvoidMain(){stringurl="www.google.cn";Console.WriteLine(GetPage(url));}}