4
votes

How to detect the mouse click outside the component? I'm making custom calendar and when clicking the TLabel with presented date - the TCalendar is appearing. It's working. But I want to disappear the TCalendar when mouse is outside the component and button is pressed? In VCL I might use the WindowsMessages, but there is a Firemonkey and I want to use it at iOS too.

BR

1
What about hiding the Calendar when it loses focus? All visual controls have an OnExit event. Alternatively, when showing the Calendar, you might try calling its protected Capture() method (or set its AutoCapture property to true) so it captures all mouse events.Remy Lebeau
OnExit doesn't exists in FMX's TCalendar...Wojtek
As I said earlier, all visual controls have an OnExit event. It is inherited from TControl. And OnExit is definitely published in TCalendar. Check the declaration of TCalendar in FMX.Calendar.pas for yourself, you will see this is true: TCalendar = class(TCustomCalendar) published ... { Events } property OnExit; ... end;Remy Lebeau

1 Answers

3
votes

Try this. It gets mouse pos on screen (Win, iOs, Android). So you can use this to find when the cursor is out of your control. And for MouseDown try using MouseDown on Form.

function MousePos: TPointF;
var
  MouseService: IFMXMouseService;
begin
  if TPlatformServices.Current.SupportsPlatformService(IFMXMouseService, IInterface(MouseService)) then
    Exit(MouseService.GetMousePos);
  Result := PointF(0, 0);
end;