2

I'm using a component TGridlayout into a form in a FireMonkey Mobile Application.

I would like to create, at runtime, buttons with color, text and image. I am using TColorbutton and Timage components, but TColorbutton only shows the picture and color. The text entered in the Text property does not appear.

https://i.stack.imgur.com/nUN0S.png

How can I create buttons (with color, image and text) dynamically?

1 Answers1

2

You have to create a Tlabel dinamically inside the button. The example is here:

var btn:TColorButton;
var testo:TLabel;

       btn:=TColorButton.Create(panTastiera);
       btn.Width:=200;
       btn.Height:=65;
       btn.Parent:=Form1;
       btn.Position.X:=10;
       btn.Position.Y:=10;

       testo:=TLabel.Create(btn);
       testo.Text:='Button 1';
       testo.OnClick:=btn.OnClick;
       testo.Parent:=btn;
       testo.FontColor:=$ffffff;
       testo.TextAlign:=TTextAlign.Center;
       testo.AutoSize:=true;
       testo.Align:=TAlignLayout.Client;

Note: "panTastiera" used in TColorButton.Create parameter, is a tpanel on the main form

To add image you can do the same, creating Timage dinamically. In my original code I created an array of buttons as the image shows

enter image description here

Gianluca Colombo
  • 717
  • 17
  • 38