16,749
社区成员
发帖
与我相关
我的任务
分享
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, Contnrs;
type
TForm1 = class(TForm)
Memo1: TMemo;
Button1: TButton;
Button2: TButton;
FontDialog1: TFontDialog;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private declarations }
FLabelList: TObjectList;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
function GetMax(Lines: TStrings):Integer;
var
i,j: integer;
s: string;
begin
Result := 0;
for i := 0 to Lines.Count - 1 do
begin
s := Copy(Lines.Strings[i],0,Pos(':',Lines.Strings[i]) - 1);
j := StrToInt(s);
if j > Result then
Result := j;
end;
end;
var
i, j, k, iMax: Integer;
Img: TImage;
s: string;
Lb: TLabel;
begin
FLabelList.Clear;
iMax := GetMax(Memo1.Lines);
Img := TImage.Create(Self);
with Img.Canvas do
begin
try
Img.Visible := False;
Font.Assign(Memo1.Font);
iMax := TextWidth(IntToStr(iMax));
for i := 0 to Memo1.Lines.Count - 1 do
begin
s := Copy(Memo1.Lines.Strings[i],0,Pos(':',Memo1.Lines.Strings[i]) - 1);
j := TextWidth(s);
k := Memo1.Left;
lb := TLabel.Create(Self);
with lb do
begin
Font := Memo1.Font;
Width := 200;
Visible := True;
Name := 'Label' + IntToStr(i);
Caption := Memo1.Lines.Strings[i];
Left := k + iMax - j;
Top := i * (Height + 2) + 30;
Parent := Self;
FLabelList.Add(lb);
end;
end;
finally
Img.Free;
end;
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
if FontDialog1.Execute then
begin
Memo1.Font.Assign(FontDialog1.Font);
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
FLabelList := TObjectList.Create(True);
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
FLabelList.Free;
end;
end.