Welcome to Dream.In.Code
Become a VB.NET Expert!

Join 150,112 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 1,946 people online right now. Registration is fast and FREE... Join Now!




Drag and drop image in vb.net 2008

 
Reply to this topicStart new topic

Drag and drop image in vb.net 2008

cutieann12
9 Nov, 2008 - 10:19 PM
Post #1

New D.I.C Head
*

Joined: 7 Nov, 2008
Posts: 2

Hello everyone i'm new in vb.net 2008 and i need to make an application that will enables it's users in a drag and drop application, does anyone knows how do this? Thank you so much..
User is offlineProfile CardPM
+Quote Post

kasbaba
RE: Drag And Drop Image In Vb.net 2008
10 Nov, 2008 - 06:41 AM
Post #2

D.I.C Head
**

Joined: 3 Nov, 2008
Posts: 53



Thanked: 7 times
My Contributions
Hi,

Before we begin, there a few points to note :

1) The AllowDrop property of the control must be set to True
2) If more than one files are being collectively being dropped on a control, you can determine if you want to use only one file or use the entire collection.
3) You can also determine the type of file/data being dropped on a control and whether you want to allow it.

There are three events associated with a common drag-drop operation.

DragEnter : When the mouse enters the control carrying the data/files to be dropped.

Please note that Dataformats Class given in the code below has some predefined formats.

For instance :
  1. If files are being dropped then use : DataFormats.FileDrop
  2. If Image is being dropped then use : DataFormats.Bitmap
  3. If a text string is being dropped then use : DataFormats.Text


'Check if the type of Drop is a FILE
CODE

Private Sub YourControlName_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles YourControlName.DragEnter

If (e.Data.GetDataPresent(DataFormats.FileDrop)) Then
            '---determine if this is a copy or move---
            If (e.KeyState And CtrlMask) = CtrlMask Then
                e.Effect = DragDropEffects.Copy
            Else
                e.Effect = DragDropEffects.Move
            End If
             '---change the border style of the control---
            yourcontrol.borderstyle = BorderStyle.FixedSingle
End If

End Sub


'Check if the type of Drop is a TEXT
CODE

Private Sub YourControlName_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles YourControlName.DragEnter

If (e.Data.GetDataPresent(DataFormats.Text)) Then
            '---determine if this is a copy or move---
            If (e.KeyState And CtrlMask) = CtrlMask Then
                e.Effect = DragDropEffects.Copy
            Else
                e.Effect = DragDropEffects.Move
            End If
            '---change the border style of the control---
            yourcontrol.borderstyle = BorderStyle.FixedSingle

End If

End Sub


DragLeave : When the mouse leaves the control

all you need to do here is set the BorderStyle property back to None

CODE

Private Sub YourControlName_DragLeaveByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles YourControlName.DragLeave

yourcontrol.borderstyle = none

End Sub


DragDrop : This is where the actual process of drop takes place.

The example below illustrates the use of File Drag-Drop
'Use this code in the Drag-Drop event of the Control

CODE

Private Sub YourControlName_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles YourControlName.DragDrop
Dim theFiles() As String = CType(e.Data.GetData("FileDrop", True), String())

            For Each theFile As String In theFiles

            Next
End Sub


The example below illustrates the use of Text Drag-Drop
'Use this code in the Drag-Drop event of the Control

CODE

Private Sub YourControlName_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles YourControlName.DragDrop

Dim DATaa = e.Data.GetData(DataFormats.Text).ToString()

End Sub


Hope this helps..


kasbaba
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/9/09 01:09AM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live VB.NET Help!

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month