Home All Groups Group Topic Archive Search About

Pasting from the clipboard

Author
13 Jan 2006 2:46 AM
hamil
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.

Author
13 Jan 2006 7:40 AM
Cor Ligthert [MVP]
Hamil,

There are many (good) samples for that in MSDN.

http://msdn2.microsoft.com/en-us/library/system.windows.forms.clipboard.aspx

I hope this helps,

Cor
Author
13 Jan 2006 6:37 PM
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





Show quoteHide quote
"Cor Ligthert [MVP]" wrote:

> Hamil,
>
> There are many (good) samples for that in MSDN.
>
> http://msdn2.microsoft.com/en-us/library/system.windows.forms.clipboard.aspx
>
> I hope this helps,
>
> Cor
>
>
>
Author
14 Jan 2006 7:31 AM
Cor Ligthert [MVP]
Author
15 Jan 2006 5:13 AM
hamil
Works perfectly, I never would have figured this out on my own.
Thanks
Hamil.


Show quoteHide quote
"Cor Ligthert [MVP]" wrote:

> Hamil,
>
> I made this sample.
>
> http://www.vb-tips.com/default.aspx?ID=59f68564-b7a6-47a0-89ff-2c40276ff588
>
> I hope this helps,
>
> Cor
>
>
>