2016-11-26 61 views
4

如何檢測組件外部的鼠標點擊? 我正在製作自定義日曆,當點擊提交日期的TLabel時 - TCalendar正在出現。它正在工作。但是當鼠標位於組件之外並且按下按鈕時,我想消失TCalendar?在VCL中,我可能會使用WindowsMessages,但有一個Firemonkey,我也想在iOS上使用它。Delphi 10.1 Firemonkey - 檢測組件外部的鼠標

BR

+1

如何隱藏日曆,當它失去了重點?所有視覺控件都有['OnExit'](http://docwiki.embarcadero.com/Libraries/en/FMX.Controls.TControl.OnExit)事件。或者,在顯示日曆時,您可以嘗試調用其受保護的['Capture()'](http://docwiki.embarcadero.com/Libraries/en/FMX.Controls.TControl.Capture)方法(或設置其[[ AutoCapture'](http://docwiki.embarcadero.com/Libraries/en/FMX.Controls.TControl.AutoCapture)屬性爲true),以便捕獲所有鼠標事件。 –

+0

OnExit在FMX的TCalendar中不存在... – Wojtek

+0

如前所述,**所有可視控件都有一個['OnExit'](http://docwiki.embarcadero.com/Libraries/Berlin/en/FMX.Controls .TControl.OnExit)事件**。它是從'TControl'繼承的。 'OnExit'肯定是[**發佈在'TCalendar' **](http://docwiki.embarcadero.com/Libraries/Berlin/en/FMX.Calendar.TCalendar_Events)。檢查'FMX.Calendar.pas'中'TCalendar'的聲明,你會發現這是真的:'TCalendar = class(TCustomCalendar)published ... {Events} property OnExit; ...結束;' –

回答

2

試試這個。它在屏幕上獲得鼠標位置(Win,iOs,Android)。所以你可以用它來找出光標何時不在你的控制之下。對於MouseDown,請嘗試在Form上使用MouseDown。

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