OLE Drag & Drop - Is this possible?
I've got a listbox and some textboxes.
The user drags people's names from the listbox to the one of the empty textboxes.
Right now when you drag a name out of the listbox you see the standard VB/Windows mouse icons for drag & drop.
Is there a way I can make the mouse icon appear as the name they are dragging??
For example, if I were to click on the name "Willy Wonka" in the listbox, could I make it so that the text comes out of the listbox and is moved around with the mouse button.
Basically, instead of seeing mouse icons they'd see the regular mouse arrow and then just under it they'd see the text "Willy Wonka".
Re: OLE Drag & Drop - Is this possible?
Anyone??
Bueller....bueller......?
Re: OLE Drag & Drop - Is this possible?
You could try something like this code which uses two text boxes. One the user drags from, the other acts as drag icon.
Place the code in a form
VB Code:
Option Explicit
Private Declare Function SetCapture Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function ReleaseCapture Lib "user32" () As Long
Dim IsCaptured As Boolean
Private Sub StartCapture(hwnd As Long)
With Text1
.Left = Text2.Left
.Top = Text2.Top
.Width = Text2.Width
.Height = Text2.Height
'.BackStyle = 0
.ZOrder 0
.Text = Text2.Text
.Visible = True
End With
Me.MousePointer = vbArrow
SetCapture Me.hwnd
IsCaptured = True
End Sub
Private Sub StopCapture()
ReleaseCapture
IsCaptured = False
Text1.Visible = False
End Sub
Private Sub Form_Load()
With Text1
.Visible = False
.ForeColor = &H80000003
.BackColor = &H80000004
.Appearance = 0
End With
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If IsCaptured Then
With Text1
.Top = Y
.Left = X
End With
End If
End Sub
Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 And IsCaptured Then
StopCapture
End If
End Sub
Private Sub Text2_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then
StartCapture Me.hwnd
End If
End Sub