Link to home
Start Free TrialLog in
Avatar of wzm
wzm

asked on

Drag & Drop

Hi All,

  I would like to drag a text file onto a text box.(content of text file).I wonder how..


Thank U very Much
w.







Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

Hi wzm, the easier way is use the Rich Text Box Control rather than Text Box Control:

Private Sub Form_Load()
    RichTextBox1.OLEDragMode = rtfOLEDragManual
    RichTextBox1.OLEDropMode = rtfOLEDropManual
End Sub

Private Sub RichTextBox1_OLEDragDrop(Data As RichTextLib.DataObject, Effect As Long, Button As Integer, Shift As Integer, x As Single, y As Single)
    RichTextBox1.LoadFile Data.Files(1)
End Sub
Avatar of glass_cookie
glass_cookie

Hi!

Do this:

Download...
http://www.vb-helper.com/Howto/oledrop.zip
Description: Process files dragged onto a form (2K)

Use this code for the textbox instead.  The only problem is that you'll have to figure whatever 2 OLE dragdrop properties that you'll have to set.  I think it's Manual then Automatic.

Load the file upon getting the filepath.

That's it!

glass cookie : )

PS. I assume you know how to load a text file.
Avatar of wzm

ASKER

Glass Cookie - Nop I don't know (load a text file) - Please
share with me, Thanks
Avatar of wzm

ASKER

Glass Cookie - Nop I don't know (load a text file) - Please
share with me, Thanks
OK... code coming up... (gimmie a few min...)
Here's the code...

Dim F As Integer
F = FreeFile
Open "C:\MyFile.txt" For Input As #F
MyTextbox.Text = Input(LOF(1), 1)
Close F
End If

where "C:\MyFile.txt" is the filepath of your file, MyTextbox is the dstination textbox to stuff all the text to and you can replace it with some other control like Label1.Caption or just a string.

That's it!

glass cookie : )

PS. Happy programming : )
Here's how the code should be:

Text1 > OLEDragMode set to 1 - Automatic, OLEDropmode set to 1 - Manual

Private Sub MyTextbox_OLEDragDrop(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single)

Dim txt As String
Dim fname As Variant

For Each fname In Data.Files
txt = txt & fname & vbCrLf
Next fname
'MsgBox txt '-Show filepath

Dim F As Integer
F = FreeFile
Open txt For Input As #F
MyTextbox.Text = Input(LOF(1), 1)
Close F
End If

' Indicate we did nothing with the files.
Effect = vbDropEffectNone

End Sub
ASKER CERTIFIED SOLUTION
Avatar of glass_cookie
glass_cookie

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of wzm

ASKER

You Deserved it Guru.