Einzelnen Beitrag anzeigen

Benutzerbild von Stevie
Stevie

Registriert seit: 12. Aug 2003
Ort: Soest
4.016 Beiträge
 
Delphi 10.1 Berlin Enterprise
 
#23

Re: Form schließen wenn Mauszeiger d.Form verläßt ?

  Alt 24. Jun 2004, 12:36
Ich hab mal etwas rumgebastelt:
Delphi-Quellcode:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private-Deklarationen } 

  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

uses Unit2;

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
  Point: TPoint;
begin
  with TForm2.Create(Self) do
  begin
    Point.X := Button1.Left;
    Point.Y := Button1.Top + Button1.Height;
    Point := Self.ClientToScreen(Point);
    Left := Point.X;
    Top := Point.Y;
    Show;
  end;
end;

end.
Delphi-Quellcode:
unit Unit5;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs;

type
  TForm2 = class(TForm)
    procedure FormCreate(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
    procedure WMMouseLeave(var Message: TWMMouse); message WM_MOUSELEAVE;
    procedure WMMouseMove(var Message: TWMMouseMove); message WM_MOUSEMOVE;
  end;

var
  Form2: TForm2;

implementation

{$R *.dfm}

procedure TForm2.WMMouseLeave(var Message: TWMMouse);
var
  Point: TPoint;
begin
  GetCursorPos(Point);
  if not PtInRect(BoundsRect, Point) then
    Close;
end;

procedure TForm2.WMMouseMove(var Message: TWMMouseMove);
var
  EventTrack: TTrackMouseEvent;
begin
  EventTrack.dwFlags := TME_LEAVE;
  EventTrack.hwndTrack := Handle;
  EventTrack.cbSize := SizeOf(EventTrack);
  TrackMouseEvent(EventTrack);
  inherited;
end;

procedure TForm2.FormCreate(Sender: TObject);
begin
  BorderStyle := bsNone;
end;

end.
BorderStyle hab ich auf bsNone gesetzt, weil es dann korrekt funktioniert...
Stefan
“Simplicity, carried to the extreme, becomes elegance.” Jon Franklin

Delphi Sorcery - DSharp - Spring4D - TestInsight
  Mit Zitat antworten Zitat