Problem Source: http://www.cnblogs.com/del/archive/2008/06/14/1218771.html#1225859
Code File:
Unit unit1; interfaceuses windows, messages, sysutils, variants, classes, graphics, controls, forms, dialogs; Type tform1 = Class (tform) Procedure formmousedown (Sender: tobject; button: tmousebutton; shift: tshiftstate; X, Y: integer); Procedure formmousemove (Sender: tobject; shift: tshiftstate; X, Y: integer); Procedure formmouseup (Sender: tobject; button: tmousebutton; shift: tshiftstate; X, Y: integer); Procedure formclick (Sender: tobject); end; var form1: tform1; implementation {$ R *. DFM} // Method 1: Use the onmousedown event parameter procedure tform1.formmousedown (Sender: tobject; button: tmousebutton; shift: tshiftstate; X, Y: integer ); in the begin // parameter, X and Y are the coordinates of the current mouse position. // For example, see: Text: = format ('onmousedown: x = % d; y = % d ', [x, y]); end; // Method 2: Use the onmousemove event parameter procedure tform1.formmousemove (Sender: tobject; shift: tshiftstate; X, Y: integer ); in the begin // parameter, X and Y are the coordinates of the current mouse position. // For example, see: Text: = format ('onmousemove: x = % d; y = % d ', [x, y]); end; // method 3: Use the onmouseup event parameter procedure tform1.formmouseup (Sender: tobject; button: tmousebutton; shift: tshiftstate; X, Y: integer); X in the begin // parameter, Y is the coordinates of the current mouse position // For example, show: showmessagefmt ('onmouseup: x = % d; y = % d ', [x, y]); end; // Method 4: Use the API function getcursorpos: Procedure tform1.formclick (Sender: tobject); var PT: tpoint; begin getcursorpos (PT ); {This is the obtained coordinate relative to the screen} PT: = screentoclient (PT); {conversion cost coordinate} showmessagefmt ('api function getcursorpos: x = % d; y = % d', [PT. x, PT. y]); end.
Form file:
Object form1: tform1 left = 0 Top = 0 caption = 'form1' clientheight = 206 clientwidth = 339 color = clbtnface font. charset = default_charset font. color = clwindowtext font. height =-11 font. name = 'tahoma 'font. style = [] oldcreateorder = false onclick = formclick onmousedown = formmousedown onmousemove = formmousemove onmouseup = formmouseup pixelsperinch = 96 textheight = 13end