*.hpp
public: // User declarations int GetTextWidth(String AText,TFont *AFont);
*.cpp
int TfrmMain::GetTextWidth(String AText,TFont *AFont) { TTextLayout *TextLayout = TTextLayoutManager::TextLayoutForClass(TTextLayoutManager::DefaultTextLayout); try { TextLayout->BeginUpdate(); try { TextLayout->Text = AText; TextLayout->MaxSize = TPointF(1000, 1000); TextLayout->WordWrap = false; TextLayout->Font = AFont; TextLayout->HorizontalAlign = TTextAlign::Leading; TextLayout->VerticalAlign = TTextAlign::Leading; } __finally { TextLayout->EndUpdate(); } return TextLayout->TextRect.Width()+6; } __finally { TextLayout->Free(); } } ....... editButton->Width=GetTextWidth(editButton->Text,editButton->Font)+8;
Комментариев нет:
Отправить комментарий