Enabling the Horizontal Scroll Bar in TListBox

Date: 27 February 1997
Author: Christopher Kohlhoff

To enable the horizontal scroll bars in your listbox, just do the following:

If your listbox is part of a dialog, make sure that you have checked "Horz Scroll" in its properties. If the listbox is being created dynamically, modify it to include the WS_HSCROLL style like so:

TMyDialog::TMyDialog(TWindow* parent, int resId)
: TDialog(parent, resId)
{
  List = new TListBox(this000200200);
  List->Attr.Style |= WS_HSCROLL;
}

Then, in your SetupWindow function, make a call to SetHorizontalExtent. This determines how far the list will scroll horizontally.

void TMyDialog::SetupWindow()
{
  TDialog::SetupWindow();

  // ...

  List->SetHorizontalExtent(500);

  // ...
}

You can also set the horizontal extent at other later times. For example, you may want to adjust the scrolling range depending on the width of the widest item in the listbox.