@@ -10,7 +10,7 @@ interface
1010 Character, DateUtils, laz.VirtualTrees, SynEdit, SynCompletion, fphttpclient, IntfGraphics, FPImage,
1111 { $IFDEF WINDOWS} Windows, Registry, uDarkStyleParams, { $ENDIF} DelphiCompat,
1212 dbconnection, dbstructures, jsonregistry, lazaruscompat, fpjson, SynEditKeyCmds, LazFileUtils, gettext, LazUTF8,
13- IniFiles, GraphType, Sockets, Contnrs
13+ IniFiles, GraphType, Sockets, Contnrs, StdCtrls
1414 { $IFDEF DARWIN} , MacOSAll { $ENDIF} ;
1515
1616type
@@ -170,6 +170,11 @@ TWinControlHelper = class helper for TWinControl
170170 procedure TrySetFocus ;
171171 end ;
172172
173+ TCustomComboBoxHelper = class helper for TCustomComboBox
174+ public
175+ procedure AutoSizeItemWidth ;
176+ end ;
177+
173178 // TSimpleKeyValuePairs = TDictionary<String, String>;
174179
175180 TAppSettingDataType = (adInt, adBool, adString);
@@ -3531,6 +3536,29 @@ procedure TWinControlHelper.TrySetFocus;
35313536 end ;
35323537end ;
35333538
3539+ { TCustomComboBoxHelper }
3540+
3541+ procedure TCustomComboBoxHelper.AutoSizeItemWidth ;
3542+ var
3543+ I, TextW, MaxTextW, MaxW: Integer;
3544+ ExtraPad: Integer;
3545+ begin
3546+ MaxW := Scale96ToForm(500 );
3547+
3548+ Canvas.Font.Assign(Font);
3549+ ExtraPad := Canvas.TextWidth(' ' );
3550+ if Items.Count > DropDownCount then
3551+ Inc(ExtraPad, Canvas.TextWidth(' ' )); // leave space for scrollbar
3552+ MaxTextW := 0 ;
3553+ for I := 0 to Items.Count - 1 do
3554+ begin
3555+ TextW := Canvas.TextWidth(Items[I]) + ExtraPad;
3556+ if TextW > MaxTextW then
3557+ MaxTextW := TextW;
3558+ end ;
3559+
3560+ ItemWidth := Min(MaxTextW, MaxW);
3561+ end ;
35343562
35353563{ TAppSettings }
35363564
0 commit comments