如何给listbox加上水平滚动条.或者让他能够自动换行!谢谢各位大侠了!只要我实验正确,马上给分的!永远在线等待!

解决方案 »

  1.   

    自动换行?如何换法?是否下面的意思?
    listbox.itemindex:=listbox.itemindex+1
      

  2.   

    不是的,我的意思是说如果我在一个edit中输入一句较长的话,然后让他在listbox中显示,希望它能根据listbox的宽度自动换行!
      

  3.   

    晕死?你查看EDIT的属性麻,
    看看它有几种切换方式,虽然根据listbox的宽度自动换行!
    QQ:81547122
      

  4.   

    Delphi 的 TListBox元件自动实现了垂直的滚动条,当ListBox不能显示全部的菜单(Item)时,这个垂直的滚动条就会出现。然而,当菜单的宽度比ListBox宽时水平的滚动条却不会出现。以下的程序就是处理这个问题的。 在你的Form的OnCreate事件中添加以下代码: 
    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; 以上的代码首先得到ListBox中最长Item的长度,然后用LB_SETHORIZONTALEXTENT消息设置ListBox的水平滚动的宽度,宽度加2是为了给右面留2个点的边。 
      

  5.   

    上面那个人的代码不适合,我的问题是listbox里的item是随时都在增加的,不是事先预定好的。怎么可能得到最长的item的代码呢?yang95801的意思我不懂,说清楚点!谢谢!
      

  6.   

    你把ScrollWidth加大不就的了。
      

  7.   

    没有人可以解决这个问题吗?或者有更好的方法,不用listbox,因为这是一个聊天程序,就算是scrollwidth再大也有可能不够用的阿,最好是能自动换行阿!各位大侠,帮帮忙阿!这个东西我今天晚上就要交工了!
      

  8.   

    To :  humn() 
    可以在初始化的时候用它,那么在你程序中的任何一个地方都可以用它。
    给你一个思路你可以继续扩展。等着别人给你喂啊...........真想说声,I服了Y
      

  9.   

    在《Delphi案例教程》(中科多媒体电子出版社)中的第203页有专题。
      

  10.   

    ihihonline怎么没有开qq阿,我就是很笨,你喂一次吧!我现在那里去找那本书阿,拜托跟我说说!
      

  11.   

    给listbox加上水平滚动条
    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
      ExtCtrls, StdCtrls;type
      TForm1 = class(TForm)
        Panel1: TPanel;
        ListBox1: TListBox;
        Button1: TButton;
        procedure FormCreate(Sender: TObject);
        procedure Button1Click(Sender: TObject);
        procedure ListBox1Enter(Sender: TObject);
      private
        MaxWidth:Integer;
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.FormCreate(Sender: TObject);
    var
      i:integer;
    begin
      MaxWidth:=0;
      for i:=1 to 20 do
      begin
        ListBox1.Items.Add('AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA');
      end;
    end;procedure TForm1.Button1Click(Sender: TObject);
    var i: integer; 
    begin
      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;procedure TForm1.ListBox1Enter(Sender: TObject);
    {var i: integer;}
    begin
    {   在这里使用ListBox将自动出现水平滚动条 }
    {  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;end.
    有问题请发信息到我的E-mail:[email protected]