{вычисляет ширину отображаемой строки в пикселях}
function TCustomDegEdit.CalcWidthInPixels: Integer;
var
aBitMap: TBitMap;
RealLenStrInPixel : Integer;
Suffix, DefInp, DefOut, strResult : String;
begin
Suffix:= Concat(StringOfChar('4', FAngularVal.FAccuracy), ' ');
Case FAngularVal.FFmtInpDeg of
degDms : DefInp:= Concat('±444_44_44_', Suffix);
DegDm : DefInp:= Concat('±444_4444', Suffix);
end;
Case FAngularVal.FFmtOutDeg of
degDms : DefOut:= Concat('±444_44_44_', Suffix);
DegDm : DefOut:= Concat('±444_4444', Suffix);
end;
if UTF8Length(DefInp) >= UTF8Length(DefOut) then
strResult:= DefInp
else
strResult:= DefOut;
aBitmap:= TBitMap.Create;
try
aBitMap.Canvas.Font.Assign(self.Font);
if aBitMap.Canvas.TryLock then
begin
RealLenStrInPixel:= aBitMap.Canvas.TextWidth(Self.Text);
Result:= aBitmap.Canvas.TextWidth(strResult);
aBitMap.Canvas.Unlock;
Result:= Math.Max(Result, RealLenStrInPixel);
end;
finally
FreeAndNil(aBitmap);
end;
end;
Добрый вечер
Чтобы особо не заморачиваться (перенапрегаться) Вы должны определить самый широкий символ в используемом шрифте и составить из него строку по длине (по количеству символов) равную исходной (наверное так быстрее). Моя функция расчитана на цифры. Самая широкая цифра по-моему 4 (четыре). Функция работает на Win-7(32), На остальных OS проверить нет возможности
Good evening
In order not to bother too much (overstrained), you must determine the widest character in the font used and compose a string from it in length (by the number of characters) equal to the original (probably faster this way). My function is for numbers. The widest figure in my opinion is 4 (four). The function works on Win-7 (32), On other OS there is no way to check