Author: Tomas Rutkauskas How to scroll a TListBox with keyboard FlushLeft, Left, Right, FlushRight Answer: 1 uses 2 math; 3 4 {$R *.dfm} 5 6 procedure TForm1.FormCreate(Sender: TObject); 7 var 8 i, n: Integer; 9 begin 10 for i := 0 to 25 do 11 listbox1.items.add(StringOfChar(Char(33 + i), Random(50) + 50)); 12 canvas.Font := listbox1.font; 13 n := 0; 14 for i := 0 to listbox1.Items.count - 1 do 15 n := Max(n, canvas.TextWidth(listbox1.Items[i])); 16 listbox1.ScrollWidth := n; 17 end; 18 19 procedure TForm1.SpeedButton1Click(Sender: TObject); 20 begin 21 Scrolllistbox(SB_LEFT); 22 end; 23 24 procedure TForm1.SpeedButton2Click(Sender: TObject); 25 begin 26 Scrolllistbox(SB_PAGELEFT); 27 end; 28 29 procedure TForm1.SpeedButton3Click(Sender: TObject); 30 begin 31 Scrolllistbox(SB_PAGERIGHT); 32 end; 33 34 procedure TForm1.SpeedButton4Click(Sender: TObject); 35 begin 36 Scrolllistbox(SB_RIGHT); 37 end; 38 39 procedure TForm1.ScrollListbox(scrollcode: Word); 40 begin 41 listbox1.perform(WM_HSCROLL, scrollcode, 0); 42 listbox1.perform(WM_HSCROLL, SB_ENDSCROLL, 0); 43 end; 44 45 initialization 46 randomize; 47 end.