Board index » delphi » I need a hortizontal scroll bar in a TListbox

I need a hortizontal scroll bar in a TListbox

I have listbox where the text being added is longer than the visual
area.  I would like for a hortizontal scroll bar to appear and all
scrolling left and right.

Does anyone know how to do this?

 

Re:I need a hortizontal scroll bar in a TListbox


Drop the TScrollBar component into the listbox.
Hope this helps.

Matt (ISD, Inc.) <isoft...@atl.mindspring.com> wrote in article
<572khn$...@camel4.mindspring.com>...

Quote
> I have listbox where the text being added is longer than the visual
> area.  I would like for a hortizontal scroll bar to appear and all
> scrolling left and right.

> Does anyone know how to do this?

Re:I need a hortizontal scroll bar in a TListbox


Quote
> Matt (ISD, Inc.) <isoft...@atl.mindspring.com> wrote in article
> <572khn$...@camel4.mindspring.com>...
> > I have listbox where the text being added is longer than the visual
> > area.  I would like for a hortizontal scroll bar to appear and all
> > scrolling left and right.

> > Does anyone know how to do this?

Use lb_SetHorizontalExtent.

Example :

var longest : LongInt;

...

  longest := 0;

  While ... do
    //while filling your ListBox (LB) store the length of the longest
string
    begin
      LB.Items.Add(aText);
      if LB.Canvas.TextWidth(aText) > longest then
             longest := LB.Canvas.TextWidth(aText);
      ...
    end;

  //after filling : set the horizontal extent of your LB with a few
pixels extra
  SendMessage(LB.Handle, lb_SetHorizontalExtent, longest + 20, 0);

Cheers,

Erwin Meekers.

Re:I need a hortizontal scroll bar in a TListbox


Quote
Matt (ISD, Inc.) wrote:

> I have listbox where the text being added is longer than the visual
> area.  I would like for a hortizontal scroll bar to appear and all
> scrolling left and right.

> Does anyone know how to do this?

I think a simple way to do this is to drop a TScrollBox (with both
scrollbars) on the form an then make it your TListBox's Parent.

Let me know if it works.

Hope this helps.

Bye

Re:I need a hortizontal scroll bar in a TListbox


Quote
Erwin Meekers <emeek...@luc.ac.be> wrote:
>Use lb_SetHorizontalExtent.

Thanks so much...this worked perfectly....:=)

Re:I need a hortizontal scroll bar in a TListbox


Quote
Matt (ISD, Inc.) wrote:

> I have listbox where the text being added is longer than the visual
> area.  I would like for a hortizontal scroll bar to appear and all
> scrolling left and right.

> Does anyone know how to do this?

No problem! Here's how (although it's somewhat cumbersome):

1) First, create a new type derived from Delphi's standard
   TListBox class. In it, just override the CreateParams() method,
   like such:

      type
         TMyListBox = class(TListBox)
         protected
            procedure CreateParams(var Params: TCreateParams); override;
         end;

2) Next, declare a variable of this type in your Form's public section.
   Like this:

      Form1 = class(TForm)
         {...}
      public
         MyListBox: TMyListBox;
         {...}
      end;

3) Then, implement the override of the CreateParams() method for your
   new TListBox type.  Make sure you specify the new listbox style
   attribute: LBS_MULTICOLUMN.  Like so:

      procedure TMyListBox.CreateParams(var Params: TCreateParams);
      begin
           inherited CreateParams(Params);
           with Params do
              Style := Style or LBS_MULTICOLUMN;
      end;

4) In your Form's OnCreate() event handler, create an instance of your
   new TListBox type and assign it the public variable of your Form.
   Make sure to set some properties, items, values, etc. so you can
   see your new horizontal listbox at runtime!  Like this:

      var
         i: Integer;
      begin
           {...}
           MyListBox := TMyListBox.Create(Form1);
           with MyListBox do
              begin
              Parent := Form1;
              Top := 50;
              Left := 50;
              Perform(LB_SETCOLUMNWIDTH, 500, 0);
              for i := 0 to 100 do
                 Items.Add(IntToStr(i));
              end;
           {...}
       end;

5) Finally, make sure you cleanup the instance of your new TListBox
   type in your Form's OnDestroy() event handler.  Such as:

      procedure TForm1.FormDestroy(Sender: TObject);
      begin
           MyListBox.Free;
      end;

Have fun!
-Jim Rofkar.

Re:I need a hortizontal scroll bar in a TListbox


isoft...@atl.mindspring.com (Matt (ISD, Inc.)) wrote:

Quote
>I have listbox where the text being added is longer than the visual
>area.  I would like for a hortizontal scroll bar to appear and all
>scrolling left and right.
>Does anyone know how to do this?

Sorry for my english.
The best way is to send a message to your listbox.
You can send it in your procedure (formcreate)  like that

procedure TForm1.FormCreate(Sender: TObject);
begin
      SendMessage(Listbox1.Handle, LB_SetHorizontalExtent, 1000, Longint(0));
 end;

Bye!
Eric from France

Re:I need a hortizontal scroll bar in a TListbox


Quote
pas...@info.utovrm.it,Usenet writes:

>> I have listbox where the text being added is longer than the visual
>> area.  I would like for a hortizontal scroll bar to appear and all
>> scrolling left and right.

>> Does anyone know how to do this?

Try this:

Quote
>sendmessage(ListBox.Handle, LB_SetHorizontalExtent, PixelWidth , 0);

[]s

--
+-----------------------------------------------------------+
|     Marcos Tito P. Marques     |     WIM Informtica      |
|   marcost...@metalink.com.br   |   http://www.wim.com.br  |
|      B.H. - M.G. - Brazil      |   marcost...@wim.com.br  |

Other Threads