//Use the default MaxLength. procedure TForm1.Edit1Change(Sender: TObject); begin //Assume the charactor's length is 50 if Length(Edit1.Text)*50 > Edit1.Width then begin Edit1.Width:=Edit1.Width+50; end; end; //if the length is not enough,The TEdit will auto stentch. //Good Luck.
begin
edit1.MaxLength:=length(edit1.Text);
end;
procedure TForm1.Edit1Change(Sender: TObject);
begin
//Assume the charactor's length is 50
if Length(Edit1.Text)*50 > Edit1.Width then
begin
Edit1.Width:=Edit1.Width+50;
end;
end;
//if the length is not enough,The TEdit will auto stentch.
//Good Luck.
begin
edit1.MaxLength:=length(edit1.Text);
end;应该可以
begin
Edit1.Width := Canvas.TextWidth(Edit1.Text) + 8;
end;引用TForm的Canvas来检测字符串宽度
begin
edit1.MaxLength:=length(edit1.Text);
edit1.width:=Canvas.TextWidth(Edit1.Text) + 8;end;