Delphi Programming

  1. Home
  2. Computing & Technology
  3. Delphi Programming

Use arrow keys to move between controls

By Zarko Gajic, About.com

The UP and DOWN arrow keys are virtually useless in edit controls. So why not use them for navigating between fields. If you set the KeyPreview property of a form to True you can use the following code snippet in the OnKeyDown event of the form to control navigation.

~~~~~~~~~~~~~~~~~~~~~~~~~
procedure TForm1.FormKeyDown(
     Sender : TObject;
     var Key: Word;
     Shift : TShiftState
   ) ;
var
   Direction : Integer;
begin
   Direction := -1;
   case Key of
     VK_DOWN, VK_RETURN : Direction := 0; {Next}
     VK_UP : Direction := 1; {Previous}
   end;
   if Direction <> -1 then
   begin
     Perform(WM_NEXTDLGCTL, Direction, 0) ;
     Key := 0;
   end;
end;
~~~~~~~~~~~~~~~~~~~~~~~~~

Delphi tips navigator:
» Open an applet from the Control Panel
« Make an Application window full screen

Zarko Gajic
Guide since 1998

Zarko Gajic
Delphi Programming Guide

Explore Delphi Programming

About.com Special Features

Delphi Programming

  1. Home
  2. Computing & Technology
  3. Delphi Programming
  4. Coding Delphi Applications
  5. Delphi Tips and Tricks
  6. 2000 Delphi Tips
  7. Use arrow keys to move between controls

©2009 About.com, a part of The New York Times Company.

All rights reserved.