I understand AutoSize does nothing
I played around with ResizeOptions like Max but whatever i do i can't get the labelEx to have a Max width.
A workaround is to get '...'behind the text if it does not fit , and put the complete value in the hint:
- Code: Select all
procedure IMSetText(var ALabel: TIWCGJQLabelEx);
var
Width: Integer;
i : Integer;
WPunt: Integer;
function CalcTextWidth(const AText : String; const AFont: TFont) : Integer;
var
bmp: TBitmap;
begin
bmp := TBitmap.Create;
try
bmp.Canvas.Font.Assign(AFont);
Result := bmp.Canvas.TextWidth(AText);
finally
bmp.Free;
end;
end;
begin
Width := CalcTextWidth(ALabel.Text, TFont(ALabel.Font));
if (Width > ALabel.Width) then
begin
WPunt := CalcTextWidth('...', TFont(ALabel.Font));
i := Length(ALabel.Text);
while (Width > (ALabel.Width - WPunt)) do
begin
Width := CalcTextWidth(Copy(ALabel.Text, 1, i), TFont(ALabel.Font));
i := i - 1;
end;
ALabel.Hint := ALabel.Text;
ALabel.Text := Copy(ALabel.Text, 1, i) + '...';
end;
end;
Eric