首页  编辑  

COMCOBOX下拉水平宽度

Tags: /超级猛料/VCL/(Check|List|ComBo)BOX/   Date Created:
use CB_SETDROPPEDWIDTH
Like:
procedrue Tform1.FormShow(Sender : Tobjects)
begin
 comboBox1.Perform(CB_SETDROPPEDWIDTH, 100, 0);
end;

procedure TForm1.ComboBox1DropDown(Sender: TObject);
var
 I: Integer;
 vMaxWidth: Integer;
begin
 vMaxWidth := TComboBox(Sender).Width;
 for I := 0 to TComboBox(Sender).Items.Count - 1 do
   vMaxWidth := Max(vMaxWidth,
     TComboBox(Sender).Canvas.TextWidth(TComboBox(Sender).Items[I]) + 8);
 TComboBox(Sender).Perform(CB_SETDROPPEDWIDTH, vMaxWidth, 0);
end;