Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firemonkey ColorDialog

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.

like image 960
DNR Avatar asked Apr 11 '26 13:04

DNR


1 Answers

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;
like image 67
RRUZ Avatar answered Apr 13 '26 10:04

RRUZ



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!