Reputation: 1659
I'm searching for an easy way to make the user select a color, in VCL I've always used the TColorDialog (VCL.Dialogs), but there either is no equivalent in FMX or I'm just not able to find it.
I could obviousely make my own color dialog using the existing components, but I thought there might be an easier & more elegant solution. I also thought about directly using Windows ChooseColor, but I'd need some sample code on how to wrap that; also this would not translate to Mac which is not an immediate issue but might impose problems later on.
Upvotes: 3
Views: 1258
Reputation: 136391
For a cross-platform solution you can build you own dialog using the FMX components like TColorPanel, TColorPicker and so on. How you are asking about a wrapper for the Windows ChooseColor Dialog this is a very simple sample 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;
Upvotes: 4