How can I do this (text on image problem)? lazarus / 8-Other ---------------------------------------------------------------------- Anonymous · 2006-02-01 16:06 Hi, This is my first try using graphics on Lazarus (and on anything else too and I have a problem :  I want the person to be able to write text on a picture. The problem I'm having is if the text entered is too long, it will go out of the picture. I would like to have this : the size of the text would fit the image, centered, using the biggest font possible, if the text is too long, it would go on another line and, if needed the font size would be reduced. I tried a couple of things but failed... I would really appreciate any help on this point. You will find the code (up to where it still works) so far below : Quoteunit Unit1; {$mode objfpc}{$H+} interface uses   Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, ExtCtrls, Jpegforlazarus,  ComCtrls, StdCtrls, Imagesforlazarus; type   { TForm1 }   TForm1 = class(TForm)     ColorButton1: TColorButton;     GroupBox1: TGroupBox;     Image1: TImage;     LabeledEdit1: TLabeledEdit;     PageControl1: TPageControl;     TabSheet1: TTabSheet;     TabSheet2: TTabSheet;     TabSheet3: TTabSheet;   procedure ColorButton1ColorChanged(Sender: TObject);     procedure FormShow(Sender: TObject);     procedure LabeledEdit1KeyUp(Sender: TObject; var Key: Word;       Shift: TShiftState);   private     { private declarations }   public     { public declarations }   end; var   Form1: TForm1; implementation { TForm1 } procedure TForm1.LabeledEdit1KeyUp(Sender: TObject; var Key: Word;   Shift: TShiftState); begin   Image1.canvas.Font.Height:=25;   Form1.Image1.Canvas.TextOut(20,20,LabeledEdit1.Text); end; procedure TForm1.ColorButton1ColorChanged(Sender: TObject); begin    Image1.Canvas.Brush.Color:=ColorButton1.ButtonColor;    Image1.Canvas.FillRect(Rect(0,0,Image1.Width, image1.height)); end;         procedure TForm1.FormShow(Sender: TObject); begin   Image1.Canvas.Brush.Color:=ColorButton1.ButtonColor;   Image1.Canvas.FillRect(Rect(0,0,Image1.Width, image1.height)); end; initialization   {$I unit1.lrs} end. ---------------------------------------------------------------------- matthijs · 2006-02-01 16:54 Use Image1.Canvas.TextWidth() to determine the width of the string on the canvas. Then decrease Canvas.Font.Size until your string fits. If size is negativ decrease font.height. ---------------------------------------------------------------------- Anonymous · 2006-02-01 23:14 Thanks a lot... I will try to make it handle the line change and so on if too big... Thanks again