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

Use arrow keys to move between controls

By , About.com Guide

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

Explore Delphi Programming
About.com Special Features

Holiday Central

What to eat, where to go, fun things to do and how to save money on the perfect gifts. More >

Family Tech Center

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

  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.