Drop file on textarea: prevent filename being added to textarea

I have a container control containing a canvas. On the canvas are a number of controls such as buttons and textareas. I want the user to be able to drop a file anywhere on the canvas (including on any of the controls on the canvas) and have the canvas’s dropobject event fire. The canvas has me.AcceptFileDrop("special/any") in its open event.

This works OK if the drop takes place on the canvas itself or on a button. But if the drop is on a textarea then the file’s path is added to the textarea’s content.

How do I prevent this and have the drop handled by the canvas? I tried having a dragenter event on a textarea and, whether I return true or false, makes no difference.

The trick here seems to work:


Yes. I tried doing an acceptfiledrop in the textarea - then it became clear that I’d have to handle the actual drop there too. The dragenter event fires, but seems to do nothing.

macOS has a system wide drag and drop text functionality. You can select text, and drag it between any text entry in almost any app because of it. This functionality also allows the drag and drop of files to turn their path into text (TextEdit, Terminal) or accept their filename.

You’re probably looking for a declare if you really really want to turn it off, that or make the TextArea ReadOnly.

Who cares ? Here, as earlier said, I can drop a .txt file on the TextArea and nothing is set in the TextArea !

Fortunately, I do not trashed the test (unlike usual); Events:

Function DragEnter(obj As DragItem, action As Integer) As Boolean
Return True
End Function

Sub Open()
End Sub

These txo are TextArea Events, nothing else.

Remember: I searched the forum, found an answer and implement it. I do not had the answer.

DropObject is the event you need to deal with for the Text Area
Open the file, extract the contents, and put it into the TextArea.

Sub DropObject(obj As DragItem, action As Integer) Handles DropObject
  if obj.TextAvailable then 
  else if obj.FolderItemAvailable then 
    dim txtStream as TextInputStream
  end if
End Sub