473,714 Members | 3,077 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

drag-drop file form explorer

I haven't worked much with drag/drop but I am trying to make a form that
accepts files to drug onto it from explorer and droped and have the form
know the full path and file name of the files dropped onto it.. does anyone
have any examples of this? thanks
Nov 21 '05 #1
5 10156
Key phrases are: Setting component property to "AllowDrop=True ", handling
DragOver and DragDrop, fetching available formats with GetDataPresent and
finally getting the data with GetData.

Example below:


Public Class Form1
Inherits System.Windows. Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeCompo nent()
'Add any initialization after the InitializeCompo nent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Disp ose()
End If
End If
MyBase.Dispose( disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.Componen tModel.IContain er
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents ListBox1 As System.Windows. Forms.ListBox
<System.Diagnos tics.DebuggerSt epThrough()> Private Sub InitializeCompo nent()
Me.ListBox1 = New System.Windows. Forms.ListBox
Me.SuspendLayou t()
'
'ListBox1
'
Me.ListBox1.All owDrop = True
Me.ListBox1.Loc ation = New System.Drawing. Point(8, 8)
Me.ListBox1.Nam e = "ListBox1"
Me.ListBox1.Siz e = New System.Drawing. Size(608, 238)
Me.ListBox1.Tab Index = 0
'
'Form1
'
Me.AutoScaleBas eSize = New System.Drawing. Size(5, 13)
Me.ClientSize = New System.Drawing. Size(624, 253)
Me.Controls.Add (Me.ListBox1)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout (False)
End Sub
#End Region
Private Sub ListBox1_DragOv er(ByVal sender As Object, ByVal e As
System.Windows. Forms.DragEvent Args) Handles ListBox1.DragOv er
If e.Data.GetDataP resent("FileDro p") Then
e.Effect = DragDropEffects .Copy
Else
e.Effect = DragDropEffects .None
End If
End Sub

Private Sub ListBox1_DragDr op(ByVal sender As Object, ByVal e As
System.Windows. Forms.DragEvent Args) Handles ListBox1.DragDr op
If e.Data.GetDataP resent("FileDro p") Then
ListBox1.Items. Clear()

Dim theFiles() As String = CType(e.Data.Ge tData("FileDrop ", True), String())
For Each theFile As String In theFiles
ListBox1.Items. Add(theFile)
Next
End If
End Sub
End Class

"Brian Henry" <no****@nospam. com> wrote in message
news:O9******** ******@tk2msftn gp13.phx.gbl...
I haven't worked much with drag/drop but I am trying to make a form that
accepts files to drug onto it from explorer and droped and have the form
know the full path and file name of the files dropped onto it.. does anyone
have any examples of this? thanks

Nov 21 '05 #2
"Brian Henry" <no****@nospam. com> schrieb:
I haven't worked much with drag/drop but I am trying to make a form that
accepts files to drug onto it from explorer


How To Provide File Drag-and-Drop Functionality in a Visual Basic .NET
Application
<URL:http://support.microso ft.com/?scid=kb;EN-US;306969>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
Nov 21 '05 #3
thanks both of you thats a big help, just one last question... how do you
generally find out what type of data is being dropped when you do a drag
drop? i know you know that this is a "FileDrop" bit of data, but if i was to
like drag a message from outlook into my app, how would i find out what the
data type was from that drop event?

"Robin Tucker" <id************ *************@r eallyidont.com> wrote in
message news:db******** ***********@new s.demon.co.uk.. .
Key phrases are: Setting component property to "AllowDrop=True ", handling
DragOver and DragDrop, fetching available formats with GetDataPresent and
finally getting the data with GetData.

Example below:


Public Class Form1
Inherits System.Windows. Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeCompo nent()
'Add any initialization after the InitializeCompo nent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Disp ose()
End If
End If
MyBase.Dispose( disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.Componen tModel.IContain er
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents ListBox1 As System.Windows. Forms.ListBox
<System.Diagnos tics.DebuggerSt epThrough()> Private Sub
InitializeCompo nent()
Me.ListBox1 = New System.Windows. Forms.ListBox
Me.SuspendLayou t()
'
'ListBox1
'
Me.ListBox1.All owDrop = True
Me.ListBox1.Loc ation = New System.Drawing. Point(8, 8)
Me.ListBox1.Nam e = "ListBox1"
Me.ListBox1.Siz e = New System.Drawing. Size(608, 238)
Me.ListBox1.Tab Index = 0
'
'Form1
'
Me.AutoScaleBas eSize = New System.Drawing. Size(5, 13)
Me.ClientSize = New System.Drawing. Size(624, 253)
Me.Controls.Add (Me.ListBox1)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout (False)
End Sub
#End Region
Private Sub ListBox1_DragOv er(ByVal sender As Object, ByVal e As
System.Windows. Forms.DragEvent Args) Handles ListBox1.DragOv er
If e.Data.GetDataP resent("FileDro p") Then
e.Effect = DragDropEffects .Copy
Else
e.Effect = DragDropEffects .None
End If
End Sub

Private Sub ListBox1_DragDr op(ByVal sender As Object, ByVal e As
System.Windows. Forms.DragEvent Args) Handles ListBox1.DragDr op
If e.Data.GetDataP resent("FileDro p") Then
ListBox1.Items. Clear()

Dim theFiles() As String = CType(e.Data.Ge tData("FileDrop ", True),
String())
For Each theFile As String In theFiles
ListBox1.Items. Add(theFile)
Next
End If
End Sub
End Class

"Brian Henry" <no****@nospam. com> wrote in message
news:O9******** ******@tk2msftn gp13.phx.gbl...
I haven't worked much with drag/drop but I am trying to make a form that
accepts files to drug onto it from explorer and droped and have the form
know the full path and file name of the files dropped onto it.. does
anyone have any examples of this? thanks


Nov 21 '05 #4
Brian Henry schrieb:
thanks both of you thats a big help, just one last question... how do you
generally find out what type of data is being dropped when you do a drag
drop? i know you know that this is a "FileDrop" bit of data, but if i was to
like drag a message from outlook into my app, how would i find out what the
data type was from that drop event?


In DragEnter:

Debug.WriteLine (String.Join(vb CrLf, e.Data.GetForma ts))
Armin
Nov 21 '05 #5
On Wed, 13 Jul 2005 08:47:36 -0400, "Brian Henry" <no****@nospam. com>
wrote:
I haven't worked much with drag/drop but I am trying to make a form that
accepts files to drug onto it from explorer and droped and have the form
know the full path and file name of the files dropped onto it.. does anyone
have any examples of this? thanks


Here a fantastic introduction to drag and drop <grin>:

http://www.codeproject.com/vb/net/Tr...ragAndDrop.asp

Hope this helps

Tom
Nov 21 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
1590
by: kiran | last post by:
I am trying to implement a rubber band/image selection script. For that I need to remove the default drag behaviour on an image. I am able to do this in IE but not Netscape. Does any one have a solution? Pls look below for IE code: var moz = ((document.all)? false : true); var ie = ((document.all)? true : false); var ElementUtil = new Object(); ElementUtil.addEventListener = function(o, type, handler) {
1
1557
by: kiran | last post by:
I am trying to implement a rubber band/image selection script. For that I need to remove the default drag behaviour on an image. I am able to do this in IE but not Netscape. Does any one have a solution? Pls look below for IE code: var moz = ((document.all)? false : true); var ie = ((document.all)? true : false); var ElementUtil = new Object(); ElementUtil.addEventListener = function(o, type, handler) {
3
2755
by: NewSun | last post by:
How can i drag a datarow from a datagrid to a other control? e.g. Drag a datarow from a datagrid to a TextBox,Then display one colnumn' value of the datarow . Or Drag a cell's value to a controll and display/handle the value in the other controll. Thanks in advance.
1
371
by: Jon Cosby | last post by:
I need an event handler for dragging the cursor on a PictureBox. The existing events only include handlers for dragging and dropping objects over the controls. I'm trying to use the MouseDown and MouseUp handlers as below, but it never gets out of the while loop. this.PicBox.MouseDown += new MouseEventHandler(this.StartMapDrag); this.PicBox.MouseUp += new MouseEventHandler(this.EndMapDrag); private void StartMapDrag(object sender,...
1
2129
by: Chris | last post by:
Hi, I need to be able to detect when a drag is cancelled after it has started. Meaning: after the drag operation has begun, and the user does not complete the drag, but releases whatever's being dragged before it reaches it's supposed destination. I need something to happen at that point, and surprisingly there's no event for like DragCancelled or something in Control. So does anyone have any idea how I could do this? Thanks, Chris
0
305
by: Samuel R. Neff | last post by:
I have a typical TreeView/ListView combo and can drag from the ListView to the TreeView. I'd like to select the TreeView node that is the target of the drag operation as the ListView items are dragged around the tree. I haven't found a way to do this. Apparently TreeView.MouseMove isn't fired during the drag operation. Any suggestions or examples?
2
4896
by: vunet.us | last post by:
Hello JavaScript experts, I have a floating div which I drag all over the page. If the page has scrollbars and users drag the floating div to the very top, page scrolls up too. The problem occurs at this moment. As page scrolls up, the div gets detached from the mouse while dragging. How can I keep the floating div to always stay attached to the mouse during a dragging process and scrolling the page? Plug and Play code is a good example...
0
1110
by: =?Utf-8?B?RGF2ZQ==?= | last post by:
Being you can drag webparts from zone to zone, is there a way to control drag speed while dragging/scrolling up the page? I have a list of webparts that may go beyond the page. If a user wants to drag the bottom webpart up to the top, I was wondering if the speed of this drag/scroll action can be controlled. Thanks
0
8808
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8712
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9179
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
6638
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5959
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4729
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3160
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2525
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2113
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.