|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
1200+ fellow developers rate and compare features of the top IDEs, like Visual Studio, Eclipse, RAD, Delphi and others, across 13 categories. Enjoy this FREE Download of the IDE User Satisfaction Study by Evans Data Corporation. Download Now!
|
|
#1
|
|||
|
|||
|
Drag and Drop Controls?
I've been wanting to make a program that is like the Microsoft Visual Basic program itself, that lets the user move the controls around on the form, such as moving the buttons, and text boxes. How do I go about starting this? I've read everywhere and can't seem to find anything on it, there's only OLE and copying pictures into a program.
|
|
#2
|
|||
|
|||
|
This example shows you how to enable the user to drop and drag items between two list boxes. Add two listboxes to your form, and insert the following code.
Private Sub Form_Load() ' Populate the list List1.AddItem "James" List1.AddItem "Frederick" List1.AddItem "Ann" List1.AddItem "Paul" List1.AddItem "Sarah" List1.OLEDropMode = 1 List2.OLEDropMode = 1 End Sub ' Code managing dropping from list one ' to list two Private Sub List1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) List1.OLEDrag ' Begin dragging End Sub Private Sub List1_OLEStartDrag(Data As DataObject, AllowedEffects As Long) ' Only allow moves AllowedEffects = vbDropEffectMove ' Assign the ListBox selection to the DataObject Data.SetData List1 End Sub Private Sub List2_OLEDragDrop(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single) Dim strList As String ' Check the format of the DataObject If Not Data.GetFormat(vbCFText) Then Exit Sub ' Retrieve the text from the DataObject strList = Data.GetData(vbCFText) ' If the item was not dropped on itself If Not strList = List2.Text Then List2.AddItem strList 'Remove the item from the ListBox List1.RemoveItem List1.ListIndex End If End Sub '' '' '' Code managing dropping from list one '' to list two '' Private Sub List2_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) List2.OLEDrag ' Begin dragging End Sub Private Sub List2_OLEStartDrag(Data As DataObject, AllowedEffects As Long) ' Only allow moves AllowedEffects = vbDropEffectMove ' Assign the ListBox selection to the DataObject Data.SetData List2 End Sub Private Sub List1_OLEDragDrop(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single) Dim strList As String ' Check the format of the DataObject If Not Data.GetFormat(vbCFText) Then Exit Sub ' Retrieve the text from the DataObject strList = Data.GetData(vbCFText) ' If the item was not dropped on itself If Not strList = List1.Text Then List1.AddItem strList 'Remove the item from the ListBox List2.RemoveItem List2.ListIndex End If End Sub Hope it is helpful... |
|
#3
|
|||
|
|||
|
Drag&Drop with Itemdata
Any chance you could amend this reply to include having the list entry's itemdata field transfer with the list entry?
This code rocks! Thanks! jody |
|
#4
|
|||
|
|||
|
no reply needed
No reply needed. I figured it out.
I sorta cheated. Before the move event, i have a form-global variable record the itemdata of the list item being moved, and when it is assigned, i just assign the current global itemdata value to it's itemdata field with mystr(i think you called the contents that). Also, this code rocks enough that you can make it three list boxes ![]() All you have to do is instead of remove the item from one list, do it from both of the ones that aren't the recipient. Since one is an error, put On Error Resume Next at the top, and you are ROLLIN! A simple copy/past of list1 to list3 with renaming as needed does the rest. thanks! jody |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > Visual Basic Programming > Drag and Drop Controls? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|