Hello,
At design time I can drop a TTMSFNCBitmapContainer on the form, connect it with a TMSFNCToolBarButton and set the bitmapname in Bitmaps[0].
However at runtime I struggle with the same thing.
I started with this:
with MyButton do
begin
BitmapVisible := True;
Width := 100;
Height := 100;
Text := '';
BitmapContainer := MainForm.BitmapContainer;
Then this (it doesn't work):
Bitmaps.Add;
Bitmaps[0].BitmapName := '3Arrows_ArrowYellowRight.svg';
Alternatively I tried this:
Bitmaps.AddBitmapName('3Arrows_ArrowYellowRight.svg',1);
and also this:
With Bitmaps.Insert(0) Do
Begin
BitmapName := '3Arrows_ArrowYellowRight.svg';
End;
At each 3 approaches there wasn't the bitmap on the button.
What is the correct approach? Thank you very much!
example from Lazarus, in Delphi just change units from LCL*
to VCL*
or 'FMX*
uses
LCLTMSFNCBitmapContainer, LCLTMSFNCToolBar;
var
bmpcontainer: TTMSFNCBitmapContainer;
toolbarbmp: TTMSFNCToolBar;
procedure TForm1.FormCreate(Sender: TObject);
var
i: Integer;
begin
Randomize;
//init
bmpcontainer := TTMSFNCBitmapContainer.Create;
toolbarbmp := TTMSFNCToolBar.Create(Self);
toolbarbmp.Parent := Self;
toolbarbmp.Left := 0;
toolbarbmp.Top := 0;
toolbarbmp.Height := 40;
//bitmaps
GenerarateBitmaps;
//toolbar buttons
for i := 0 to 9 do
begin
with TTMSFNCToolBarButton.Create(toolbarbmp) do
begin
Parent := toolbarbmp;
Height := toolbarbmp.Height;
Width := 50;
Bitmaps.AddBitmap(bmpcontainer.Bitmaps[i]);
end;
end;
end;
procedure TForm1.GenerarateBitmaps;
const
carr: array [0..4] of TColor = (clRed, clLime, clAqua, clYellow, clFuchsia);
sarr: array [0..3] of TBrushStyle = (bsSolid, bsHorizontal, bsFDiagonal, bsCross);
var
i: Integer;
bmp: TBitmap;
bmpi: TTMSFNCBitmapItem;
begin
bmp := TBitmap.Create;
bmp.SetSize(bmpcontainer.Width, bmpcontainer.Height);
for i := 0 to 9 do
begin
bmp.Canvas.Brush.Color := clWhite;
bmp.Canvas.FillRect(0, 0, bmp.Width, bmp.Height);
bmp.Canvas.Brush.Style := sarr[Random(4)];
bmp.Canvas.Brush.Color := carr[Random(5)];
bmp.Canvas.RoundRect(2, 2, bmp.Width - 2, bmp.Height - 2, 3, 3);
bmpi := bmpcontainer.Items.Add;
bmpi.Bitmap.Bitmap.Assign(bmp); //or load from file: bmpi.Bitmap.LoadFromFile('file.png'); //no need to draw then
bmpi.Name := 'bmp' + IntToStr(i);
end;
bmp.Free;
end;

or by name:
Bitmaps.AddBitmap(bmpcontainer.FindBitmap('bmp' + IntToStr(i)));
Thank you very much Pawel!