Full example of Drag and Drop within a application

By | 2002-06-01

Suppose you have a listbox with some elements and want to drag&drop a selected one into a textbox. http://137.56.41.168:2080/VisualBasicSource/vbdraganddrop.txt

Original Author: Found on the World Wide Web

Code

Make a form with a textbox (text1) and a listbox (list1). Fill the listbox with some items...
Make a label (label1). Set it invisible = False
Put the next code at the appropiate places:
Sub List1_MouseDown (Button As Integer, Shift As Integer, X As Single, Y As Single)
  Dim DY
  DY = TextHeight("A")
  Label1.Move list1.Left, list1.Top + Y - DY / 2, list1.Width, DY
  Label1.Drag
End Sub
Sub List1_DragOver (Source As Control, X As Single, Y As Single, State As Integer)
  If State = 0 Then Source.MousePointer = 12
  If State = 1 Then Source.MousePointer = 0
End Sub
Sub Form_DragOver (Source As Control, X As Single, Y As Single, State As Integer)
  If State = 0 Then Source.MousePointer = 12
  If State = 1 Then Source.MousePointer = 0
End Sub
Sub Text1_DragDrop (Index As Integer, Source As Control, X As Single, Y As Single)
  text1.text = list1
  
End Sub

Author: dwirch

Derek Wirch is a seasoned IT professional with an impressive career dating back to 1986. He brings a wealth of knowledge and hands-on experience that is invaluable to those embarking on their journey in the tech industry.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.