Hi ,

Pls. give me sample code for the function drag & drop in VB

Recommended Answers


Heres a small example for you


Jump to Post

All 2 Replies

i have one for you try this:

Dim blnDrag As Boolean
Dim xClickPos, yClickPos

Private Sub btnEnableDrag_Click()
If blnDrag = False Then
blnDrag = True
btnEnableDrag.Caption = "Disable Dragging"
blnDrag = False
btnEnableDrag.Caption = "Enable Dragging"
End If
End Sub

Private Sub btnEnableDrag_DragOver(Source As Control, X As Single, Y As Single, State As Integer)
If State = 0 Then
Source.MousePointer = 12
ElseIf State = 1 Then
Source.MousePointer = 0
End If
End Sub

Private Sub Command1_Click()
If blnDrag = False Then MsgBox "Button Clicked"
End Sub
Private Sub Command1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If blnDrag Then
xClickPos = X
yClickPos = Y
Command1.Drag vbBeginDrag
End If
End Sub

Private Sub Form_DragDrop(Source As Control, X As Single, Y As Single)
Source.Left = X - xClickPos
Source.Top = Y - yClickPos
End Sub
Private Sub Form_Load()
blnDrag = False
End Sub

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.