2007. május 4., péntek

How to change the scrollbar position in a non-focused TMemo


Problem/Question/Abstract:

How to change the scrollbar position in a non-focused TMemo

Answer:

You'll have KeyPreview set true of course then:

procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
  case Key of
    VK_Down: Memo1.Perform(Messages.EM_LINESCROLL, 0, 1);
    VK_UP: Memo1.Perform(Messages.EM_LINESCROLL, 0, -1);
    {and if HorzScrollbars are also used}
    VK_Left: Memo1.Perform(Messages.EM_LINESCROLL, -1, 0);
    VK_Right: Memo1.Perform(Messages.EM_LINESCROLL, 1, 0);
  end;
  {But where is the focus when you are doing this? Do you want the keystroke passed
  elsewhere? If not then}
  Key := 0;
end;

Nincsenek megjegyzések:

Megjegyzés küldése