Click here to Skip to main content
15,902,025 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
Posted
Updated 5-Nov-11 12:02pm
v3
Comments
KairuByte 5-Nov-11 17:49pm    
So you are attempting to imitate a copy the way that ctrl + c does, but circumvent the clipboard and load the text selection directly into your textbox?
_Q12_ 5-Nov-11 17:59pm    
I really dont know how to proceed... to circumvent(avoid) the copy_to_clipboard // or to actually use it? here you came in. I want to copy into [anything] not strictly inside form1 - for example into external text file or other program... for that, my best guess is to make use of copy_to_clipboard.
But what you will come with its good for me... I want it to see it working for the moment.

PS-my mouse button #4 is using the "copy_to_clipboard" function-from its driver software.
KairuByte 5-Nov-11 18:14pm    
What do you intend to do? From the sounds of it your not sure what you need or want... Are you making a clipboard monitor? A clipboard alternative?

If you want to use clipboard you could just copy the text using ctrl + c (or your mouse button), and then have your program monitor the clipboard and do what you need to do. If you don't want to use the clipboard you will have to get a little more creative.
_Q12_ 5-Nov-11 18:23pm    
I dont know all the ways to do things - but I do know what i want/need. :)
Yes, i want to use the clipboard - if this is the Only Way.
So, how to monitor the clipboard with my program?
-BUT,I want to be sure that, the mouse ACTUALLY make the copy of selection, from webControl text at runtime!!!!!!!!!!!

1 solution

Hello,

Have you tried that:
webBrowser1.Document.ExecCommand("Copy", false, null);
textBox2.Text = Clipboard.GetText();


Valery.
 
Share this answer
 
Comments
_Q12_ 5-Nov-11 19:22pm    
YES---thats it!
Thanks and +5stars from me.
;)
LanFanNinja 5-Nov-11 21:44pm    
+5 from me too I tried to find an elegant solution to this a few years ago myself.
Sergey Alexandrovich Kryukov 5-Nov-11 23:46pm    
Sure, a 5.
--SA
thatraja 6-Nov-11 1:46am    
From me too, 5!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900