1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22:
| procedure AutoSizeComboboxList(Targetbox: TComboBox); var temp, max, itemscounter: integer; bmp : TBitmap; begin bmp := TBitmap.Create; try bmp.Canvas.Font.Assign(Targetbox.Font); max :=Targetbox.width; for itemscounter := 0 to Targetbox.Items.count-1 do begin temp := bmp.Canvas.TextWidth(Targetbox.Items[itemscounter]); if temp > max then max := temp; end; if Targetbox.Items.Count > Targetbox.DropDownCount then Inc(max, GetSystemMetrics(SM_CXVSCROLL)); Sendmessage(Targetbox.Handle, CB_SETDROPPEDWIDTH, max+20,0); finally bmp.Free; end; end; |