简体   繁体   中英

Copy Selected Area's text to clipboard

I am pretty new to C# and programming in general. I am wondering if there is a way to implement the following feature:

  1. in my C# program have a textbox (named tb1 ) and button (named bt1 ).
  2. When I click bt1 , my cursor will change to "selector"
  3. I switch to program where I need the value to be taken from
  4. I select text that I need to be copied to my C# program
  5. Selected text will appear in bt1

WindowsXP/Windows Vista/7

PS - I know how to get text from the clipboard and how to set text to the clipboard, what I need is the way to capture ANY text AFTER I press the button. For example- I have 10 textboxes; each textbox has a button.

The process would be:

  1. button1 click -> select text in another application -> which is auto-pasted to textbox1

  2. button2 click -> select text in another application -> which is auto-pasted to textbox2

  3. button3 click -> select text in another application -> which is auto-pasted to textbox3

etc.

You don't specify whether the user can click Ctrl-C in step (4) when inside that other application. If so, the selected text can indeed appear in your application: all you need to do is reading the Clipboard object, as in Clipboard.GetText() .

A good introduction with some how-to's can be found here at CodeProject .


In the case where step (4) in your question should auto-copy the selected text to the clipboard from a foreign application, consider using an automation-tool like AutoIt or the White Framework instead (more options in this question on automation: What's a good, if any, .NET Windows automation library? ).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM