Форум: "Основная";
Текущий архив: 2003.02.13;
Скачать: [xml.tar.bz2];
ВнизДлина строки Найти похожие ветки
← →
PrettyFly (2003-02-05 15:18) [0]Есть ли какая-нть функция, определеяющая длину строки, написанную данным шрифтом (в пикселях)?
← →
Skier (2003-02-05 15:21) [1]1) TCanvas.Font.Assign(...)
2) TCanvas.TextWidth(...)
← →
Игорь Шевченко (2003-02-05 15:32) [2]
function GetTextWidthInPixels(AText: string; AControl: TControl): integer;
var
propInfo: PPropInfo;
thisFont: TFont;
begin
Result := 0;
propInfo := GetPropInfo(AControl.ClassInfo, "Font");
if propInfo <> nil then begin
thisFont := TFont(GetObjectProp(AControl, "Font"));
if Assigned(thisFont) then
with TControlCanvas.Create do
try
Control := AControl;
Font.Assign(thisFont);
Result := TextWidth(AText);
finally
Free;
end;
end;
end;
← →
PrettyFly (2003-02-05 15:41) [3]Спасиба! А я думал есть стандартная фунукция...
← →
Song (2003-02-05 16:06) [4]DrawText()
← →
PrettyFly (2003-02-05 16:10) [5]
...
C := TCanvas.Create;
Res := C.TextWidth("la-la-lalala");
Показывает ошибку "Canvas does not allow drawing", почему?
← →
Skier (2003-02-05 16:35) [6]>PrettyFly
Дружище, а ведь тебе и пример уже дали...
А "Canvas does not allow drawing" потому что не задан
контекст устройства, на котором рисовать см. TCanvas.Handle
← →
PrettyFly (2003-02-05 16:55) [7]Всё заработало ;)
← →
DarkGreen (2003-02-06 05:28) [8]The GetTextExtentPoint32 function computes the width and height of the specified string of text. This function supersedes the GetTextExtentPoint function.
BOOL GetTextExtentPoint32(
HDC hdc, // handle of device context
LPCTSTR lpString, // address of text string
int cbString, // number of characters in string
LPSIZE lpSize // address of structure for string size
);
Страницы: 1 вся ветка
Форум: "Основная";
Текущий архив: 2003.02.13;
Скачать: [xml.tar.bz2];
Память: 0.45 MB
Время: 0.01 c