1. Home
  2. Computing & Technology
  3. Delphi Programming

Is mouse over Form?

By Zarko Gajic, About.com

To tell if the mouse is over Delphi Form, we can use the GetCapture() windows API function to capture the mouse. See the Windows documentation for additional information and limitations on mouse capturing.

~~~~~~~~~~~~~~~~~~~~~~~~~
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;
~~~~~~~~~~~~~~~~~~~~~~~~~

Delphi tips navigator:
» Change the Windows Start Button bitmap
« Controling sound volume from code

Zarko Gajic
Guide since 1998

Zarko Gajic
Delphi Programming Guide

Explore Delphi Programming
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. Delphi Programming
  4. Using VCL Components
  5. TMouse
  6. Is mouse over Form?

©2009 About.com, a part of The New York Times Company.

All rights reserved.