How do I get the equivalent of CTRL-A / CTRL-C in a WPF WebBrowser
I'm new to WPF and also C# so I'll try to be as specific as possible so you'll understand.
What am I trying to do?
I have a WPF Page with a WebBrowser control on it. I am navigating to a specific URL which displays perfectly in the control. Now, I would like to programmatically select all and copy the content of the webpage to my clipboard.
What have I tried
dynamic doc = webbrowser1.Document;
var htmlText = doc.documentElement.InnerText;
This however removes some formatting like empty tablecolumns so it will not be the same data as CTRL-A / CTRL-C
I have also tried the above with InnerHTML and that gives me the开发者_如何学Python HTML code. When I then paste that into an empty notepad and save it as .html file, externally open in IE and perform the CTRL-A / CTRL-C it gives me the desired result.
Any idea how to get the EXACT same result through code?!
Use the following code:
dynamic document = browser.Document;
document.ExecCommand("SelectAll", true, null);
document.ExecCommand("Copy", false, null);
精彩评论