Winform程序 2.0的. 需要引用Microsoft.mshtml.
private void Form1_Load(object sender, EventArgs e)
{
webBrowser1.Navigate("http://www.baidu.com");
webBrowser1.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(webBrowser1_DocumentCompleted);
}
void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
webBrowser1.Document.MouseUp += new HtmlElementEventHandler(Document_MouseUp);
}
void Document_MouseUp(object sender, HtmlElementEventArgs e)
{
IHTMLDocument2 document = (IHTMLDocument2)webBrowser1.Document.DomDocument;
IHTMLTxtRange htmlElem = (IHTMLTxtRange)document.selection.createRange();
string s = htmlElem.htmlText;
richTextBox1.Text = s;
}
private void Form1_Load(object sender, EventArgs e)
{
webBrowser1.Navigate("http://www.baidu.com");
webBrowser1.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(webBrowser1_DocumentCompleted);
}
void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
webBrowser1.Document.MouseUp += new HtmlElementEventHandler(Document_MouseUp);
}
void Document_MouseUp(object sender, HtmlElementEventArgs e)
{
IHTMLDocument2 document = (IHTMLDocument2)webBrowser1.Document.DomDocument;
IHTMLTxtRange htmlElem = (IHTMLTxtRange)document.selection.createRange();
string s = htmlElem.htmlText;
richTextBox1.Text = s;
}
需要看document.selection.createRange();类型 需要引用Microsoft.VisualBasic. 用Microsoft.VisualBasic.Information.TypeName(document.selection.createRange());方法查看类型.
差不多就这些了~ 不知道每次记录这些遇到的问题 能帮助别人不..- -|