How to catch coordinates of mouse cursor (IDE Delphi) when I invoke Context Menu to create a new control?
I'd like to create a new control via Context Menu at same coordinates where Context Menu was invoked.
I'm creating my own component editor to do this, then I need the coordinates of mouse to create the control there.
I don't know if I understood your question well, but there are some ways to capture position of your mouse:
Method 1 - Capture the mouse position on your screen: Here you can use
TMouseclass like this:Method 2 - Capture the mouse position on a control: Here you can use
GetCursorPos, I declared a function calledcursorCordinate, it will receive a control name (I used my form namedfrm_mainas given control but it can be any other control like a button, label or anything else) and it will return aTPointvalue containing position of mouse on given control:usage example:
Method 3 - Another way to capture the mouse position on a control: Here you can use control's
OnMouseMoveevent and itsXandYparameters, just place your code block in this event. I used it to show mouse position on my form (frm_main) in a label (lbl_cordinate_form_2), but you can use any other control'sOnMouseMoveevent:You can see the result in image; first line is result of Method 1, second line for Method 2 and third line belongs to Method 3: