unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls;
type
TForm2 =
class(TForm)
btn1: TButton;
procedure btn1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
type
TTextElement =
class(TImage)
private
FTxt:
string;
procedure RepaintElement;
public
//
constructor Create(txt:
string);
end;
var
Form2: TForm2;
implementation
{$R *.dfm}
constructor TTextElement.Create(txt:
string);
begin
inherited Create(
nil);
FTxt := txt;
RepaintElement;
end;
procedure TTextElement.RepaintElement;
var
x, y: integer;
begin
//Canvas.Font.Name := 'Arial'; // uncomment this line to produce failure
// Resize Image
Width := 200;
Height := 120;
Canvas.Brush.Color := clBtnShadow;
Canvas.FillRect(ClientRect);
Canvas.Brush.Color := clWindow;
Canvas.FillRect(Rect(3, Height - 3, Width - 3, 3));
Canvas.Pen.Color := clBtnShadow;
Canvas.Brush.Color := clBtnShadow;
Canvas.Brush.Style := bsClear;
Canvas.Font.
Name := '
Arial';
Canvas.Font.Style := [fsBold];
// Write text to canvas
x := (Width - Canvas.TextWidth(FTxt))
div 2;
y := (Height - Canvas.TextHeight(FTxt))
div 2;
Canvas.TextOut(x, y, FTxt);
Canvas.Font.Color := clBlack;
end;
procedure TForm2.btn1Click(Sender: TObject);
var
element: TTextElement;
begin
element := TTextElement.Create('
test');
element.Parent := Self;
end;
end.