【问题标题】:Firemonkey ColorDialog火猴颜色对话框
【发布时间】:2013-11-07 18:37:40
【问题描述】:

我正在寻找一种让用户选择颜色的简单方法,在 VCL 中我一直使用 TColorDialog (VCL.Dialogs),但在 FMX 中没有等效项,或者我无法找到它。

我显然可以使用现有组件制作我自己的颜色对话框,但我认为可能有一个更简单、更优雅的解决方案。我也考虑过直接使用 Windows ChooseColor,但我需要一些关于如何包装它的示例代码;这也不会转化为 Mac,这不是一个直接的问题,但可能会在以后产生问题。

【问题讨论】:

    标签: delphi firemonkey


    【解决方案1】:

    对于跨平台解决方案,您可以使用 TColorPanel、TColorPicker 等 FMX 组件构建您自己的对话框。您如何询问 Windows ChooseColor 对话框的包装器,这是一个非常简单的示例 adapted from the MSDN documentation

    uses
     System.UIConsts,
     FMX.Platform.Win,
     Winapi.Windows,
     Winapi.CommDlg;
    
    const
      MaxCustomColors = 16;
    type
      TCustomColors = array[0..MaxCustomColors - 1] of Longint;
    
    procedure TForm1.Button1Click(Sender: TObject);
    var
     cc : TChooseColor;
     acrCustClr: TCustomColors;
     hwnd : THandle;
     rgbCurrent : DWORD;
    begin
      FillChar(cc, sizeof(cc), #0);
      cc.lStructSize := sizeof(cc);
      cc.hwndOwner :=  FmxHandleToHWND(Self.Handle);
      cc.lpCustColors := @acrCustClr;
      cc.rgbResult := RGBtoBGR(claYellow);
      cc.Flags := CC_FULLOPEN OR CC_RGBINIT;
      if (ChooseColor(cc))  then
         Rectangle1.Fill.Color:= MakeColor(GetRValue(cc.rgbResult), GetGValue(cc.rgbResult), GetBValue(cc.rgbResult));
    end;
    

    【讨论】:

    • 谢谢,一如既往的魅力。有没有办法调整包装器以显示在表单的中心而不是 (0,0) ?
    • 您必须获取对话框的句柄,然后使用SetWindowPos 方法。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-07
    • 2010-12-30
    • 2019-11-24
    • 1970-01-01
    相关资源
    最近更新 更多