试一试给ListBox发一条消息LB_SETHORIZONTALEXTENT

解决方案 »

  1.   

    Also, to respond to the LB_SETHORIZONTALEXTENT message, the list box must have been defined with the WS_HSCROLL style. Then if the width of the list box is smaller than the value of wParam, the horizontal scroll bar horizontally scrolls items in the list box. If the width of the list box is equal to or greater than this value, the horizontal scroll bar is hidden. 
      

  2.   

    对,要使用API函数
    必须要使用GetWINDOWLong和SetWindowLong来设置LIST的风格之中有一个
    WS_HSCROLL;
    这样才能响应LB_SETHORIZONTALEXTENT消息。
      

  3.   

    1.做一个足够宽的listbox,放到一个容器内(如Frame)。然后写代码用滚动条滚动listbox.
    2.用MSFlexGrid代替listbox。将内容拆开成n个字符一组,放入MSFlexGrid,去掉网格线。
      

  4.   

    否定我的第二个回答,因此列表框控件缺省的创建风格里含有对水平滚动条的支持,因此只需要发消息即可:
    先建立一个新模块,然后使用API文本查看器拷贝一个关于Sendmessage的声明,和一个LB_SETHORIZONTALEXTENT常量的声明,粘贴到模块中,
    在表单的ONLOAD事件里,写以下代码:
    dim i as long
    sendmessage(list1.hwnd,LB_SETHORIZONTALEXTENT,list1.width+1,0)
    要显式说明设置的滚动条宽度比列表框宽,水平滚动条会显示出来,否则水平滚动条会消失。
      

  5.   


    //请参考下面的DELPHI程序,把它改成VB格式即可
    procedure TForm1.Button1Click(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[i]) then
        MaxWidth := ListBox1.Canvas.TextWidth(ListBox1.Items[i]);
      SendMessage(ListBox1.Handle, LB_SETHORIZONTALEXTENT, MaxWidth+2, 0);
    end;