I would like to drag and drop a file from Explorer or any other application, to my application, destination being a Rich Text Box.
How could i do that ???
Printable View
I would like to drag and drop a file from Explorer or any other application, to my application, destination being a Rich Text Box.
How could i do that ???
Figured it out. I thought I might post it for all who may need it in the future.
Here is some Drag and Drop Code that works:
Make sure the Rich TextBox's OLEDragMode and OLEDropMode are set to manual
Private Sub RichTextBox1_OLEDragDrop(Data As RichTextLib.DataObject, Effect As Long, Button As Integer, Shift As Integer, x As Single, y As Single)
' check the format of the data that is being dropped
If Data.GetFormat(vbCFFiles) = True Then
' grab the first file name in the collection of file names
sFileName = Data.Files(1)
' incase it's not a valid file display the error message
On Error GoTo invalidfile
' try to load file
Open sFileName For Input As 1
Do Until (EOF(1) = True)
RichTextBox1.Text = input$(LOF(1), 1)
Loop
Close 1
End If
Exit Sub
invalidfile:
' display the invalid file format message
MsgBox "Invalid File Format!"
End Sub
Private Sub RichTextBox1_OLEDragOver(Data As RichTextLib.DataObject, Effect As Long, Button As Integer, Shift As Integer, x As Single, y As Single, State As Integer)
' check the data to see if it is what we will allow. if not so "no drop"
If Data.GetFormat(vbCFFiles) Then
Effect = vbDropEffectCopy And Effect
Else
Effect = vbDropEffectNone
End If
End Sub
Austin Kauffman
NitsuaEnterprises.com