如何将ListBox的水平和垂直滚动条显示出来,即使没有内容,或有内容但只设置一列.

解决方案 »

  1.   

    procedure TForm1.FormCreate(Sender: TObject);
    var
    i, MaxWidth: integer;
    begin
          //水平滚动条
          MaxWidth := 0;
          for i := 0 to ListBox1.Items.Count - 1 do
          if MaxWidth < ListBox1.Canvas.TextWidth(ListBox1.Items.Strings[i]) then
          MaxWidth := ListBox1.Canvas.TextWidth(ListBox1.Items.Strings[i]);
          SendMessage(ListBox1.Handle, LB_SETHORIZONTALEXTENT, MaxWidth+2, 0);      //垂直滚动由自动系统生成
    end;