Trapping text drop on TextArea

I want to trap when the user drops (pastes) text from outside of my app. The TextArea has AcceptTextDrop in its Open event so the drop works.

Is there an event similar to DropObject (which doesn’t fire for a simple text drop) or do I have to watch the TextChange event and intercept the text dropped there while distinguishing between the change from the drop and a change from editing by the user?

Create a subclass of text area
Then you can implement DropObject (and several other things that if you just drop an instance on a layout you cant override)

I guess I’m missing something. My first question here is should the TextArea’s KeyDown event handler see a Ctrl-V as something it is supposed to deal with? I created a new project with nothing in the window except a TextArea control. The only code I added was a Break in the KeyDown event. I then copied some text from a NotePad file and used Ctrl-V to paste it into the TextArea. It pasted in fine but the KeyDown event never hit the Break statement. I then put a Breakpoint on the Break statement and tried again. Still nothing except the text showing in the TextArea.

So now I’m really confused. It’s as if the KeyDown event isn’t even firing. Is it supposed to in a case like this?

text area handles some things before you ever get a chance to IF all you do it put and instance on a layout

basically it handles certain menu items

IF you do as I suggested and create a subclass and then handle these items in a subclass you can intercept a lot of this

I’ve written about this on my blog
It had to do with menu handlers in a listbox but the text area is similar in many respects

The KeyDown event will never see the Ctrl-V keypress because it is handled by the standard EditPaste menu handler. In a subclass, as Norman suggests, you can implement your own EditPaste handler and catch it there.

That makes sense. I’ll give it a try. Thanks.

Someone wrote up for me a class for the textarea that does that.
If you like I can send it to you?

Thanks. I did get it working but I’d still like to see how other people solved it.

Link could be useful … or is that no longer allowed?


I dont think its allowed :man_shrugging:


Thanks. It’s basically the same as what I did except I didn’t bother with stripping blank lines.