Find Code:
All Words
Any of the Words
Exact Phrase
Home
:
Code
:
Forums
:
Submit
:
Mailing List
:
About
:
Contact
Code
All
VB.NET
ASP.NET
C#
VB Classic
ASP Classic
Snippets
Popular
Resources
Submit Code
Forums
Articles
Tips
Links
Books
Contest
Link to us
Drag & Drop - Move files from desktop to a textbox
Author:
Heinz Prelle
E-mail:
Click to e-mail author
Website:
http://www.visual-basic5.de
Submitted:
8/24/2008
Version:
VB 2005
Compatibility:
VB 2005, VB 2008
Category:
File Manipulation
Views:
17418
This example moves any files from desktop to a textbox. The example needs a reference to Shell32.dll
Declarations:
Imports Shell32 Imports System.IO.Path
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
Home
|
Forums
|
Submit
|
Books
|
Mailing List
|
Advertising
|
About
|
Contact
© 2024 A1VBCode. All rights reserved.
Legal disclaimer & terms of use
Privacy statement