Главная страница | назад





Article #17759: How can I tell if the mouse is over my form?

 Question and Answer Database
FAQ2759D.txt How can I tell if the mouse is over my form?
Category :VCL
Platform :All
Product :All 32 bit
Question:
How can I tell if the mouse is over my form?
Answer:
You can use the GetCapture() windows API function to
capture the mouse. See the Windows documentation for
additional information and limitations on mouse capturing.
Example:
procedure TForm1.FormDeactivate(Sender: TObject);
begin
ReleaseCapture;
end;
procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
If GetCapture = 0 then
SetCapture(Form1.Handle);
if PtInRect(Rect(Form1.Left,
Form1.Top,
Form1.Left + Form1.Width,
Form1.Top + Form1.Height),
ClientToScreen(Point(x, y))) then
Form1.Caption := 'Mouse is over form' else
Form1.Caption := 'Mouse is outside of form';
end;
7/16/98 4:31:28 PM

Last Modified: 01-SEP-99