Pasting from the clipboard

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I would like to right click and select (copy )a file (or directory) name in
Windows Explorer and then paste the file (or directory) name into a text box
on a vb.net form. Can anyone explain how to do this?
thanks.
Hamil.
 
I have tried to modify the msdn example but I have not succeeded. I have
tried their example code and it works. The example copies test from notepad
or text box. I want to be able to transfer a selected filename from a
windows explorer pane into my application, a textbox for example. The
following code, taken from msdn works for text. How would I modify it to
make it extract the filename as I have described above.

I used another example to get the dataformats from the clipboard object and
FileName was one of the items listed. However, when I try to change "text"
in the example below to 'FileName" it doesn't work.

I suspect a minor fix would solve my problem.
Thanks
Hamil.



Private Sub button2_Click(sender As Object, e As System.EventArgs)
' Declares an IDataObject to hold the data returned from the clipboard.
' Retrieves the data from the clipboard.
Dim iData As IDataObject = Clipboard.GetDataObject()

' Determines whether the data is in a format you can use.
If iData.GetDataPresent(DataFormats.Text) Then
' Yes it is, so display it in a text box.
textBox2.Text = CType(iData.GetData(DataFormats.Text), String)
Else
' No it is not.
textBox2.Text = "Could not retrieve data off the clipboard."
End If
End Sub 'button2_Click
 
Works perfectly, I never would have figured this out on my own.
Thanks
Hamil.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top