下面的例子也许对你有帮助:拖放操作
1 从我的电脑拖动文件到 Text1
2 从 Text2 拖动文字到 Text1
Private Sub Form_Load()
Text1.OLEDropMode = 1 '放操作为人工方式,自动触发 OLEDragOver(移动) 和 OLEDragDrop(放下) 事件
Text2.OLEDragMode = 1 '拖启动操作方式为自动,自动触发 OLEStartDrag、OLEGiveFeedback、OLECompleteDrag 事件
End Sub
Private Sub Text1_OLEDragDrop(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single)
'放下事件,当控件的 OLEDropMode=1 触发的 OLE 放事件
Dim I As Long, nStr As String
If Data.GetFormat(vbCFText) Then nStr = Data.GetData(vbCFText)
If Data.GetFormat(vbCFFiles) Then
For I = 1 To Data.Files.Count
nStr = nStr & Data.Files(I) & vbCrLf
Next
End If
Text1.SelText = nStr
End Sub
Private Sub Text1_OLEDragOver(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single, State As Integer)
'被拖对象在目的对象上移动,类似于 Move 事件
'在此过程中设置 Effect=0,不会触发 OLEDragDrop (放事件)
If Data.GetFormat(vbCFText) Then Exit Sub
If Data.GetFormat(vbCFFiles) Then Exit Sub
Effect = 0
End Sub
Private Sub Text2_OLEStartDrag(Data As DataObject, AllowedEffects As Long)
AllowedEffects = 2 '移动方式' 1 '复制方式
Data.SetData "我的拖动", vbCFText '取消该语句,拖动内容就是 Text2.SelText
' Data.SetData , vbCFFiles
' Data.Files.Add "E:\Documents and Settings\x-1\桌面\My1.txt"
End Sub