Recent

Author Topic: Listbox scrolling question  (Read 3251 times)

JLWest

  • Hero Member
  • *****
  • Posts: 1293
Listbox scrolling question
« on: February 27, 2018, 10:47:10 pm »
I have a listbox that I'm loading a flat string (no carriage returns) into and I want to scroll to the end of the string. 

The listbox has a property scroolwidth which is in pixels.

What value do i set scroolwidth to?

 
FPC 3.2.0, Lazarus IDE v2.0.4
 Windows 10 Pro 32-GB
 Intel i7 770K CPU 4.2GHz 32702MB Ram
GeForce GTX 1080 Graphics - 8 Gig
4.1 TB

Blaazen

  • Hero Member
  • *****
  • Posts: 3237
  • POKE 54296,15
    • Eye-Candy Controls
Re: Listbox scrolling question
« Reply #1 on: February 27, 2018, 11:24:34 pm »
ScrollWidth is something else. It should control the width of the (side) scrollbar but is probably does not work for all widgetsets (Qt, at least) and its value is default, i.e. 0.
My advice: choose other component. Maybe TMemo, some RichEdit or SynEdit.
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

JLWest

  • Hero Member
  • *****
  • Posts: 1293
Re: Listbox scrolling question
« Reply #2 on: February 27, 2018, 11:45:18 pm »
"Maybe TMemo, some RichEdit or SynEdit.

Don't understand RichEdit or SynEdit assume they are controlls somewhere.

Thanks
FPC 3.2.0, Lazarus IDE v2.0.4
 Windows 10 Pro 32-GB
 Intel i7 770K CPU 4.2GHz 32702MB Ram
GeForce GTX 1080 Graphics - 8 Gig
4.1 TB

jamie

  • Hero Member
  • *****
  • Posts: 6091
Re: Listbox scrolling question
« Reply #3 on: February 28, 2018, 12:09:38 am »
not sure of ScrollWidth will work for you but you can try this..

 ListBox.SCrollWidth := ListBox.Canvas.TextWidth(ListBox.Items[LineNumber?]);

 if that follows the Windows implementation that should make the Horizontal scrollbar appear

 If it actually scrolls that way automatically is another question!
The only true wisdom is knowing you know nothing

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: Listbox scrolling question
« Reply #4 on: February 28, 2018, 12:40:57 am »
Once your listbox is parented and populated with items, you can use the following (or an adaptation of it):
Code: Pascal  [Select][+][-]
  1.  
  2. procedure SetScrollWidthToFitAllItems(aListBox: TListBox);
  3. var
  4.   max: Integer = 0;
  5.   m, i: Integer;
  6. begin
  7.   if Assigned(aListBox) and Assigned(aListBox.Parent) then
  8.     begin
  9.       for i := 0 to aListBox.Items.Count-1 do begin
  10.         m := aListBox.Canvas.TextWidth(aListBox.Items[i]);
  11.         if m > max then
  12.           max := m;
  13.       end;
  14.       aListBox.ScrollWidth := max;
  15.     end;
  16. end;

Blaazen

  • Hero Member
  • *****
  • Posts: 3237
  • POKE 54296,15
    • Eye-Candy Controls
Re: Listbox scrolling question
« Reply #5 on: February 28, 2018, 01:01:01 am »
Sorry, I was wrong with ScrollWidth property, it is really for setting the width of area and horizontal scrollbar appears when ScrollWidth>ClientWidth.
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

 

TinyPortal © 2005-2018