unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Memo1: TMemo;
procedure Memo1KeyPress(Sender: TObject; var Key: Char);
procedure Memo1Change(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure CreateWidthSpis(const spis:TStringList; var memo:TMemo);
var
i:Integer;
maxWidth:Integer;
canvas:TCanvas;
begin
canvas:=TCanvas.Create;
try
canvas.Handle:=GetDC(memo.Handle);
canvas.Font:=memo.Font;
maxWidth:=0;
For i:=0 to spis.Count-1 do
begin
If canvas.TextWidth(spis.Strings[i])>maxWidth then
maxWidth:=canvas.TextWidth(spis.Strings[i]);
end;
finally
canvas.Free;
end;
memo.ClientWidth:=maxWidth+5;
//memo.Lines.Assign(spis);
end;
procedure TForm1.Memo1KeyPress(Sender: TObject; var Key: Char);
begin
CreateWidthSpis(TStringList(Memo1.Lines), Memo1);
end;
procedure TForm1.Memo1Change(Sender: TObject);
begin
CreateWidthSpis(TStringList(Memo1.Lines), Memo1);
end;
end.