2006. december 1., péntek

How to programmatically shift focus to the next control


Problem/Question/Abstract:

How to programmatically shift focus to the next control

Answer:

To shift focus from one control to the next in the tab order without using the tab key, set the KeyPreview property of the parent form to True and drop the following into the OnKeyPress of the first control (and every control you want to "exit" with the [programmer specified] key).

if Key = chr(XXX) then
  SendMessage(form1.Handle, WM_NEXTDLGCTL, 0, 0);

XXX = the ASCII code of a Key (e.g. ENTER = 13)

Nincsenek megjegyzések:

Megjegyzés küldése