Month: June 2018
Resizing a TCustomControl to fit TField contents
void SizeControlToField(TCustomControl* control, TField* field)
{
HDC DC;
LPTEXTMETRIC lptm = static_cast<LPTEXTMETRIC>(malloc(sizeof(TEXTMETRIC)));
DC = ::GetDC(control->Parent->Handle);
::GetTextMetrics(DC, lptm);
if (field->DataType == TFieldType::ftString) {
control->Width = field->DataSize * lptm->tmAveCharWidth;
}
free(lptm);
}