Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You could create a TTimer that polls the current mouse position every 0.10 seconds or so, then positions "AnotherComponent" according to the current mouse position.</p> <p>Then you wouldn't fire your event for every pixel of mouse movement- you won't need any OnMouseMove event on your controlling component at all.</p> <p>On my computer, this basically has no performance impact at all.</p> <pre><code>procedure TForm1.Timer1Timer(Sender: TObject); var pt: TPoint; begin //Is the cursor inside the controlling component? if so, position some //other control based on that mouse position. GetCursorPos(pt); if MouseWithin(pt.x,pt.y,MyComponent,Form1.Left,Form1.Top) then begin //replace with whatever real positioning logic you want AnotherComponent.Top := pt.y; AnotherComponent.Left := pt.x; end; end; function TForm1.MouseWithin(mouseX, mouseY: integer; const comp: TWinControl; const ParentWindowLeft: integer; const ParentWindowTop: integer): boolean; var absoluteCtrlX, absoluteCtrlY: integer; begin //take a control, and the current mouse position. //tell me whether the cursor is inside the control. //i could infer the parent window left &amp; top by using ParentwindowHandle //but I'll just ask the caller to pass them in, instead. //get the absolute X &amp; Y positions of the control on the screen //needed for easy comparison to mouse position, which will be absolute absoluteCtrlX := comp.Left + ParentWindowLeft; absoluteCtrlY := comp.Top + ParentWindowTop + GetSystemMetrics(SM_CYCAPTION); Result := (mouseX &gt;= absoluteCtrlX) and (mouseX &lt; absoluteCtrlX + comp.Width) and (mouseY &gt;= absoluteCtrlY) and (mouseY &lt;= absoluteCtrlY + comp.Height); end; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload