KeyPreview property


Available for Window and DialogBox objects.

Read/Write only at design time

Specifies whether the WM_KEYDOWN, WM_CHAR and WM_KEYUP messages will be received by the Owner window instead of the control having the input focus. It can be one of the following values:

FALSE    The three messages mentioned above are received by the control having the input focus as usual (default).
TRUE      The three messages mentioned above are received by the Owner window, that is, the window containing the controls.


When this property is set to TRUE, the WM_KEYDOWN, WM_CHAR and WM_KEYUP messages are first received by the Owner window so that they can be processed (or not) in its window procedure. By returning TRUE or FALSE the Owner window decides whether the message will be received by the child control or not. If the message returns TRUE, there will be no further processing and it will never be sent to the child control having the focus, while returning FALSE will mean that the message will also be sent to the child control having the focus. Finally, if the KeyPreview property is set to FALSE, those three messages will behave normally, that is, they will be sent to the child control having the input focus.