Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

.NET 

[VB.NET] Drag & Drop - Move files from desktop to a textbox

This example moves any files from desktop to a textbox. The example needs a reference to Shell32.dll

Declarations:
Code
Imports Shell32
Imports System.IO.Path

Code:
Code
Public Class Form1

    Private Structure FileFormat
        Public TypeFormat As String
    End Structure

    Private ff As New FileFormat

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) _
            Handles MyBase.Load
        With Me
            .CenterToScreen()
            .TextBox1.AllowDrop = True
            .ff.TypeFormat = "FileNameW"
        End With
    End Sub

    Private Function DragAndDrop_MoveLink(ByVal Filename As String) As String
        Const Filetype As String = ".lnk"
        If String.Compare(GetExtension(Filename), Filetype, True) <> 0 Then Return Filename
        Dim shell As Shell32.Shell = New Shell32.Shell
        Dim DirectoryName As Shell32.Folder = shell.NameSpace(GetDirectoryName(Filename))
        Dim Item As Shell32.FolderItem = DirectoryName.Items().Item(GetFileName(Filename))
        Dim LinkObject As Shell32.ShellLinkObject = CType(Item.GetLink, Shell32.ShellLinkObject)
        Return LinkObject.Path
    End Function

    Private Sub TextBox1_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) _
            Handles TextBox1.DragDrop
        If ff.TypeFormat = Nothing Then
            Throw New Exception("Error...")
        Else
            If e.Data.GetDataPresent(ff.TypeFormat, False) Then
                Dim Filename As System.Array = CType(e.Data.GetData(ff.TypeFormat, False), System.Array)
                TextBox1.Text = DragAndDrop_MoveLink(CType(Filename.GetValue(0), String))
            End If
        End If
    End Sub

    Private Sub TextBox1_DragOver(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) _
            Handles TextBox1.DragOver
        If ff.TypeFormat = Nothing Then
            Throw New Exception("Error...")
        Else
            If e.Data.GetDataPresent(ff.TypeFormat, False) Then
                e.Effect = DragDropEffects.Copy
            Else
                e.Effect = DragDropEffects.None
            End If
        End If
    End Sub

End Class

orignaly written by:Heinz Prelle

If You Like this tutorial,
please check out my other tutorials by clicking ==> here
PHP & .NET Contributor.
Thanks for the share mate ^_^
I think i`ll find a good use for it :3
no prblem mate..im glad you like it...
PHP & .NET Contributor.
wow.. ws in need of that..
thnx.. 🤝
(Apr 30, 2010 09:39 AM)๖ۣۜBlueAce™ Wrote:  wow.. ws in need of that..
thnx.. 🤝

yeah....lol appology accepted!! 😏
PHP & .NET Contributor.
Thank you!
Will credit you and Heinz Prelle if i use it.
I've seen a couple tutorials from you now.. Good job mate.

And last: Thanks for sharing. ✌
thank you sir....

2short
PHP & .NET Contributor.
Thank you for the share, i like this source.
(Apr 30, 2010 10:08 AM)iKorkSkalle Wrote:  Thank you!
Will credit you and Heinz Prelle if i use it.

Thank you....


please check out my other tuts here
PHP & .NET Contributor.
Awesome Mate, good work. Great Share.

Thanks.
(Apr 30, 2010 04:15 PM)TheBlackMarket Wrote:  Awesome Mate, good work. Great Share.

Thanks.

no problem


If You Like this tutorial,
please check out my other tutorials by clicking ==> here
PHP & .NET Contributor.
Thanks for this, it will come in very useful. (I hope.)
(Apr 30, 2010 04:22 PM)★Cooldude★ Wrote:  Thanks for this, it will come in very useful. (I hope.)

im glad i helped...(i hope) 😏
PHP & .NET Contributor.
Thanks for sharing nice code :)
--


Possibly Related Threads...
Thread / Author Replies Views Last Post
[.NET] by QuobiAug 6, 2022 02:23 PM 0 406 Aug 6, 2022 02:23 PM
Last Post: Quobi
[Python] by Beginner1234Nov 11, 2021 03:54 AM 2 138 Nov 11, 2021 03:54 AM
Last Post: 3phase
[C#] by draxyeeJun 5, 2020 02:58 PM 1 241 Jun 5, 2020 02:58 PM
Last Post: Porn