On Fri, Jan 25, 2013 at 4:12 PM, Art Heimsoth <firstname.lastname@example.org>
I am trying to get the horizontal scroll with a ListBox but so far am not
successful. The .rc file content for it is:
LISTBOX IDC_RPT_DETAIL, 5, 20, 402, 250, WS_TABSTOP | WS_VSCROLL | WS_HSCROLL | LBS_DROPDOWN | LBS_NOTIFY | LBS_USETABSTOPS
The vertical scroll appears to work okay. What am I missing?
Something easily missed, and missed by a lot of people. Probably a poor design from Microsoft.
A list box has a thing called the horizontal extent. When the list box is first created by the operating system the horizontal extent is set to the width of list box. Nothing is ever shown past the horizontal extent. For the horizontal scroll bar to appear, the horizontal extent must be set wider than the list box.
You do that with the list box setWidthPx() method. A typical sequence is something like this:
lb = self~newListBox('IDC_LB_CITIES')
max = 10
items = .array~of("New York New York"~copies(9), -
"San Diego California"~copies(8), -
"Los Angles Californiz"~copies(10), -
"Bakersfield California"~copies(11), -
do city over items
s = self~getTextSizePx(city)
if s~width > max then max = s~width
lb~insert( , city)
I had to add the copies() method to make the city strings wide enough.
Of course if you know ahead of time that you need, say, 220 pixels, you can skip the getTextSizePx() stuff and just do:
The benefit of the getTextSizePx() in the loop is you can come back to the program in 3 years, add a new long string, and not beat your head against the wall trying to figure why the string is clipped in the list box. ;-)