q12 Posted November 5, 2011 Posted November 5, 2011 This is a Hard question(apparently simple): How do I COPY the selected text from a webBrowser page, and paste it to a text file( for example)? I have this until now: private void webBrowser1_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e) { //the 67 is the mousebutton no4 (I have 5 5buttons and a scrolwhell-A4Tech_X7 mouse) //the mousebutton no4 is set to "ctrl+c" keys (Copy) if (e.KeyValue == 67) textBox2.Text=webBrowser1.DocumentText; } Until now i cant manage to copy a text selection from webBrowser. How to do that? Thank you. Quote
Leaders snarfblam Posted November 6, 2011 Leaders Posted November 6, 2011 This code works just fine for me. What is the problem you are having? Is the event not being raised? Or are you not getting the keycode you are expecting? private void webBrowser1_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e) { if (e.Modifiers == Keys.Control && e.KeyCode == Keys.C) { Clipboard.SetText(webBrowser1.DocumentText); } } There are some potential problems with this approach, depending on what you're doing with this program. If I select text in a textbox within the browser and try to copy it, I end up getting the page's HTML on the clipboard instead of the text selected in the textbox. You'll want to be aware of quirks like this if it's something that might be a problem. Quote [sIGPIC]e[/sIGPIC]
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.