2005. november 25., péntek

How to scroll a TListBox with keyboard FlushLeft, Left, Right, FlushRight


Problem/Question/Abstract:

How to scroll a TListBox with keyboard FlushLeft, Left, Right, FlushRight

Answer:

uses
  math;

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
var
  i, n: Integer;
begin
  for i := 0 to 25 do
    listbox1.items.add(StringOfChar(Char(33 + i), Random(50) + 50));
  canvas.Font := listbox1.font;
  n := 0;
  for i := 0 to listbox1.Items.count - 1 do
    n := Max(n, canvas.TextWidth(listbox1.Items[i]));
  listbox1.ScrollWidth := n;
end;

procedure TForm1.SpeedButton1Click(Sender: TObject);
begin
  Scrolllistbox(SB_LEFT);
end;

procedure TForm1.SpeedButton2Click(Sender: TObject);
begin
  Scrolllistbox(SB_PAGELEFT);
end;

procedure TForm1.SpeedButton3Click(Sender: TObject);
begin
  Scrolllistbox(SB_PAGERIGHT);
end;

procedure TForm1.SpeedButton4Click(Sender: TObject);
begin
  Scrolllistbox(SB_RIGHT);
end;

procedure TForm1.ScrollListbox(scrollcode: Word);
begin
  listbox1.perform(WM_HSCROLL, scrollcode, 0);
  listbox1.perform(WM_HSCROLL, SB_ENDSCROLL, 0);
end;

initialization
  randomize;
end.

Nincsenek megjegyzések:

Megjegyzés küldése