FileListBox的下方如何使用ScrollBar啊? 因为有时候文件名会很长,无法显示完整。 所以希望加上ScrollBar,使能够看到完整的文件名。

解决方案 »

  1.   

    怎么会没有人知道呢?  赶快给分!unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, FileCtrl, Grids, DBGrids;type
      TForm1 = class(TForm)
        FileListBox1: TFileListBox;
        DirectoryListBox1: TDirectoryListBox;
        DriveComboBox1: TDriveComboBox;
        procedure DirectoryListBox1Change(Sender: TObject);
      private
        { Private declarations }
        procedure SetHorizontalScrollBar(lb : TFileListBox) ;
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}
    procedure TForm1.SetHorizontalScrollBar(lb : TFileListBox) ;
    var
      j, MaxWidth: integer;
    begin
      MaxWidth := 0;
      for j := 0 to lb.Items.Count - 1 do
      if MaxWidth < lb.Canvas.TextWidth(lb.Items[j]) then
        MaxWidth := lb.Canvas.TextWidth(lb.Items[j]) ;  SendMessage(lb.Handle,
                  LB_SETHORIZONTALEXTENT,
                  MaxWidth + 5, 0) ;
    end;procedure TForm1.DirectoryListBox1Change(Sender: TObject);
    begin
      SetHorizontalScrollBar(self.FileListBox1);
    end;end.
      

  2.   

    如果DirectoryListBox和filelistbox都要水平拖动呢?