Hi,
I created descendant of TForm which implements behavior like Popup Window.
But the form is not closing itself after clicking outside of it.
I tried with SetCapture and Deactivate but still nothing happens.
unit DSPopupForm;
{$mode objfpc}{$H+}
interface
uses
Forms, Classes, LMessages;
type
{ TDSPopupForm }
TDSPopupForm = class(TForm)
protected
procedure Deactivate; override;
procedure WMLButtonDown(var AMessage: TLMLButtonDown); message LM_LBUTTONDOWN;
procedure DoClose(var CloseAction: TCloseAction); override;
public
constructor Create(TheOwner: TComponent); override;
procedure popup(x, y: Integer);
end;
implementation
uses
Controls, LCLIntf;
{ TDSPopupForm }
constructor TDSPopupForm.Create(TheOwner: TComponent);
begin
inherited Create(TheOwner);
BorderStyle := bsNone;
FormStyle := fsStayOnTop;
end;
procedure TDSPopupForm.popup(x, y: Integer);
begin
Left := X;
Top := Y;
Show;
Activate;
SetCapture(Handle);
end;
procedure TDSPopupForm.Deactivate;
begin
inherited Deactivate;
Close;
end;
procedure TDSPopupForm.WMLButtonDown(var AMessage: TLMLButtonDown);
var
MousePos: TPoint;
begin
MousePos := Mouse.CursorPos;
if not PtInRect(BoundsRect, MousePos) then
begin
Close;
end
else
begin
inherited;
end;
end;
procedure TDSPopupForm.DoClose(var CloseAction: TCloseAction);
begin
ReleaseCapture;
inherited;
end;
end.
May be you can point something I cannot see or suggest some work direction
AI suggested to use
instead of
FormStyle := fsStayOnTop;
Which I thought will make the form behave as Popup, but actually fsPopup doesn't exists at all in the enumeration.
Lazarus 4.0RC1 (rev t-fixes-4-58-g43d904ed50) FPC 3.2.2 x86_64-win64-win32/win64