I am pretty new to C# and programming in general.
I am wondering if there is a way to implement the following feature:
- in my C# program have a
textbox(namedtb1) andbutton(namedbt1). - When I click
bt1, my cursor will change to “selector” - I switch to program where I need the value to be taken from
- I select text that I need to be copied to my C# program
- 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:
-
button1 click -> select text in another application -> which is auto-pasted to textbox1
-
button2 click -> select text in another application -> which is auto-pasted to textbox2
-
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?).