How do I do copy and paste

dominico

Well-known member
Joined
Mar 9, 2005
Messages
57
Programming Experience
3-5
Hello gentlemen,

I have a child form which displays a paragraph. I will have a "Copy" button on the child form so that when I select a string in the paragraph with the mouse and click on the copy button; it will copy my selected string to the windows clipboard. After that, I want to paste that string to a text field on the parent form. I will have a "Paste" button on the parent form so that when I click it, it will paste the selected text into the parent form's text field.

Please show me how to do this. I read the msdn examples but they only show us how with using an external text file. I cannot apply it to my case.

Note: I know how to do "copy/paste" with using the shortcut keys but the users may not know how to do it this way. I want to make it easy for them.

Please advise,

Thanks

dominico
 
Last edited:
Some controls have clipboard functionality built in, check for Copy(), Paste(), Cut() methods. Otherwise, research the Clipboard class (Clipboard.SetText) etc.
 
Neal said:
Some controls have clipboard functionality built in, check for Copy(), Paste(), Cut() methods. Otherwise, research the Clipboard class (Clipboard.SetText) etc.


Hi Neal,

I can use the clipboard class. However, I am having a difficulty in writing the code on how to detecting the textbox that has the focus for pasting the data. I have several textboxes on the main form. So when a user click on the paste button, how do we know which textbox that has the focus to paste it to.

Please advise.
 
Try something like this:
VB.NET:
[color=Blue]Dim [/color]enteredTextBox [color=Blue]As[/color] TextBox
[color=Blue]Private Sub[/color] AllTextBoxes_Enter([color=Blue]ByVal [/color]sender [color=Blue]As[/color] Object, [color=Blue]ByVal[/color] e [color=Blue]As[/color] System.EventArgs) [color=Blue]Handles [/color]TextBox1.Enter, TextBox2.Enter
	enteredTextBox = [color=Blue]CType[/color](sender, TextBox)
[color=Blue]End Sub[/color]
I think you user must click on a certain textbox first before they actually paste date into them... the code above should be able to trace which textbox is the current one that a user chooses.
Hope this helps...
 
ayozzhero said:
Try something like this:
VB.NET:
[color=blue]Dim [/color]enteredTextBox [color=blue]As[/color] TextBox
[color=blue]Private Sub[/color] AllTextBoxes_Enter([color=blue]ByVal [/color]sender [color=blue]As[/color] Object, [color=blue]ByVal[/color] e [color=blue]As[/color] System.EventArgs) [color=blue]Handles [/color]TextBox1.Enter, TextBox2.Enter
	enteredTextBox = [color=blue]CType[/color](sender, TextBox)
[color=blue]End Sub[/color]
I think you user must click on a certain textbox first before they actually paste date into them... the code above should be able to trace which textbox is the current one that a user chooses.
Hope this helps...

Hi ayozzhero,

Thank you. It works!

Have a great day.

dominico
 
Back
Top