[Solved] Drag and drop an image file onto a page with more than one TPanel lazarus / 31-LCL ---------------------------------------------------------------------- Paul1986 · 2021-02-02 03:14 I have a multi page application that can have several TPanels on a page.  The panels display images that can be merged in a variety of ways. I'd like to add a drag and drop option  so a user can drop an image file onto one of the TPanels.  AllowDropFiles is enabled for the form and I figured out a way of identifying the page the file was dropped onto but I can't figure how to identify the intended TPanel. To identify the page concerned I used the TPageControl.ActivePage property that seems to be reliable.  What I want to know is the name/id of the panel on which the image was dropped.  I've tried the focus events but that didn't work.  Do I have to start tracking the mouse? ---------------------------------------------------------------------- jamie · 2021-02-02 22:07 TheControl := MyPageorTabSheet.ControlAtPos(Point(X,Y), Flase {Don't allow disabled}); If TheControl is TPanel then..... ---------------------------------------------------------------------- lucamar · 2021-02-02 23:17 I was thinking about something on that line; the problem is that OnDropFiles doesn't tell you where the files where dropped so you'd have to keep track of the mouse position with OnMouseMove (or the current control with OnMouseEnter/ONMouseLeave) handlers. But then you'll have to track for all controls (or at lest all interested control) and the coordinates (if using OnMouseMove) are then control- relative. Sure, no big deal, but a litttle tedious and a bit error prone ... So to answer the OP's question: yes, I think you'll have to track the mouse ... ---------------------------------------------------------------------- Paul1986 · 2021-02-03 06:05 Thanks for the help.  Based on the above, and another post about ControlAtPos I found in a 2019 thread, I have this piece of code that seems to work: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i        mPos := ScreenToClient(Mouse.CursorPos);        aControl := ImagePages.ActivePage.ControlAtPos(mPos, [capfRecursive,capfAllowWinControls]);        if (aControl = nil) then        begin          Form1.MemoRecord.Lines.Add('Hmm - nil/null control');        end else        begin          if (aControl is TPanel) then          begin            Form1.MemoRecord.Lines.Add('Control is ' + aControl.GetNamePath);          Form1.MemoRecord.Lines.Add('Mouse X: ' + IntToStr(mPos.x) + ', Y: ' + IntToStr(mPos.y));          end else          begin            Form1.MemoRecord.Lines.Add('Not a TPanel control');          end;      end;                When debugging and stopping at a breakpoint, I was getting some negative positions for the mouse location so I wonder it that is a side effect of the debugger.  So I added some debug lines to record the mouse position and the numbers look about right. Thanks again for your help.    This thread can be closed/solved thanks. ---------------------------------------------------------------------- lucamar · 2021-02-03 09:38 Quote from: Paul1986 on February 03, 2021, 07:05:17 amThanks again for your help.    This thread can be closed/solved thanks. It's a nice solution that you found To mark as solved, edit your first post and add [SOLVED] at the front of the "Subject" line. ---------------------------------------------------------------------- Paul1986 · 2021-02-03 11:52 Quote from: lucamar on February 03, 2021, 10:38:25 am... To mark as solved, edit your first post and add [SOLVED] at the front of the "Subject" line. Thanks,  I should have known that but its been a while since I was last here.