我需要在我的 Firemonkey 桌面项目中使用自定义光标。
我可以在 VCL 项目中使用 LoadCursorFromFile 在我的项目中加载自定义光标。
我尝试对 Firemonkey 执行相同的操作,但它没有加载光标。
有没有什么工作方法可以在 Firemonkey 中实现加载自定义光标?
uses Winapi.Windows;
procedure Tform1.Button1Click(Sender: TObject);
const mycursor= 1;
begin
Screen.Cursors[mycursor] := LoadCursorFromFile('C:\...\Arrow.cur');
Button1.Cursor := mycursor;
end;
我只在 Mac 上这样做,但总体思路是您实现自己的 IFMXCursorService。请记住,这几乎是一种全有或全无的方法。您还必须实现默认的 FMX 光标。
type
TWinCursorService = class(TInterfacedObject, IFMXCursorService)
private
class var FWinCursorService: TWinCursorService;
public
class constructor Create;
procedure SetCursor(const ACursor: TCursor);
function GetCursor: TCursor;
end;
{ TWinCursorService }
class constructor TWinCursorService.Create;
begin
FWinCursorService := TWinCursorService.Create;
TPlatformServices.Current.RemovePlatformService(IFMXCursorService);
TPlatformServices.Current.AddPlatformService(IFMXCursorService, FWinCursorService);
end;
function TWinCursorService.GetCursor: TCursor;
begin
// to be implemented
end;
procedure TWinCursorService.SetCursor(const ACursor: TCursor);
begin
Windows.SetCursor(Cursors[ACursor]); // you need to manage the Cursors list that contains the handles for all cursors
end;
可能有必要向 TWinCursorService 添加一个标志,以便防止 FMX 框架覆盖您的光标。
注册您自己的光标服务时,时机很重要。这必须在 FMX 调用 TPlatformServices.Current.AddPlatformService(IFMXCursorService, PlatformCocoa); 之后完成。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)