Click here to Skip to main content
15,903,203 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I would like to be able to copy a text that I load into a textbox in a C# program to the clipboard and that the copied text is pasted in an other window (out side of the C# program) after a 4 second timer.
I'm not sure how to handle the copy / paste bit of this.
Also the text should be copied in to different fields of the other program using tab.
Any ideas on those issues?

Only 1 program is a third-party, the source program is one we will develop in house.
We actually need the in-house program to copy the text which I loaded into it and paste it in the third-party program.
My actual question is what C# code should I use to be able to automatically copy the text and automatically paste it when I click in the third-party program textbox.
Posted
Updated 7-Feb-13 23:41pm
v2
Comments
Zoltán Zörgő 8-Feb-13 5:15am    
Both are third party programs?
Nomardus 8-Feb-13 5:28am    
Only 1 program is a third-party, the source program is one we will develop in house.
We actually need the in-house program to copy the text which I loaded into it and paste it in the third-party program.
My actual question is what C# code should I use to be able to automatically copy the text and automatically paste it when I click in the third-party program textbox.

The copy part is easy, just use the Clipboard Class[^] and put your data into it. The pasting will have to be done by the receiving program, but you can signal it with a Windows message, such as WM_PASTE[^].
 
Share this answer
 
Comments
Nomardus 8-Feb-13 5:47am    
Richard,

The problem is that we can't access the source code of the receiving program simply because we aren't allowed.
Is there a way that the sending program can paste it into the receiving program by just clicking in the receiving program?
Richard MacCutchan 8-Feb-13 6:30am    
The only way you could do it is to find the window handle of an edit control in the receiving program, and send the WM_PASTE message to that control. However there is no guarantee that the control will accept it. You could talk to the people that own the receiving program for help.
C#
private void CopyTemplate()
       {
           TimerText.Text = "Copying";
           SendKeys.SendWait("{HOME}");
           SendKeys.SendWait("Update ticket on ticket: ");
           SendKeys.SendWait("{TAB}");
           SendKeys.SendWait("Regarding ticket: " + ValueCopy + "");
           SendKeys.SendWait("{ENTER}");
           SendKeys.SendWait("Summary: ");
           SendKeys.SendWait("{TAB}{TAB}{TAB}");
           SendKeys.SendWait("{ENTER}");
           SendKeys.SendWait("+{TAB}+{TAB}+{TAB}");
           SendKeys.SendWait("{ENTER}{ENTER}");

           textBox1.SelectAll();
           textBox1.Copy();
           SendKeys.SendWait("^{V}");

           SendKeys.SendWait("{ENTER}{ENTER}{ENTER}{ENTER}{ENTER}");
           SendKeys.SendWait("{TAB}{TAB}{TAB}");
           SendKeys.SendWait("{ENTER}");
           SendKeys.SendWait("+{TAB}+{TAB}+{TAB}");

           SendKeys.SendWait("{ENTER}{ENTER}");
           SendKeys.SendWait("{TAB}{TAB}{TAB}{TAB}");
           SendKeys.SendWait("{ENTER}");
           SendKeys.SendWait("+{TAB}+{TAB}+{TAB}+{TAB}");

           TimerText.Text = "Done";
           StartDoneTimer();
       }
 
Share this answer
 

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