3 Answers
3

Here's some example code that would handle a message on the frame to be able to navigate to the next control when Enter is pressed. Note that this sample does not modify the Enter key to become a Tab key. Instead it selects the next control and prevents further processing of the key down message.

Also note that the code may require further tweaking. One for, if any of the controls actually need to process the Enter key, for instance a TMemo, you need to add an exception. Second for, the navigation is wrapped in the frame, i.e. after the last frame control the first frame control is focused - not a control on the form and not on the frame. For these, you might want to add conditions for the message return, if you want default processing on some condition simply call inherited without doing any other thing.

This is fine if your frame only ever appears on a form on which the only controls that can receive focus are the ones on that single frame. If you are in that very specific situation, then this answer is fine. In a more general situation you need the code to live on the form. Well, you could try to make it work elsewhere but why? The form is the right place for it.
– David HeffernanMar 12 '13 at 23:17

It was a strange behaviour. On the frame there is TScrollBox where some TLabel and TEdit controls are placed. I've attached the proposed code to frame, and, when I press ENTER, the focus changed from first TEdit to last one and then it was disapeared! I need to press ENTER key four or five times only after that it appeared again in first TEdit. What is the problem? Where focus is moved, to the parents: TScrollBox, TFrame, TForm?
– Ivan ZMar 12 '13 at 23:20

You ask how to do this in a frame. It's not possible to handle dialog navigation in a frame. That's done by the form for fairly obvious reasons. So you'll need somehow to splice this code into the form that hosts your frame.

For a memo control this will have no effect. They will treat pressing ENTER as input of a line break. But I presume that's what you would wish to happen. Otherwise the memo control would be completely unusable.

@anondv Did I get anything wrong in this answer
– David HeffernanMar 11 '13 at 14:36

It's a pitty that it is not possible in a frame. But I'm understand the reason, if a form has many frames on it, it is necessary to write only one event handler for all of them. Thank you!
– Ivan ZMar 11 '13 at 14:48

1

The reason is really that if the focus is on the last control in one frame, then TAB needs to move to the first control in the next frame. And since each frame is isolated, then the frame cannot be in charge of that. Only the form can see the big picture of all the controls that are on it. And that's why CM_DIALOGKEY is sent to the parent form.
– David HeffernanMar 11 '13 at 15:00

Thanks for this answer--it's exactly what I needed when I went searching for a solution to my problem. I've hooked into OnKeyDown and OnKeyPress before, but I've got multiple frames on multiple tabs of a page control and my tried-and-true methods just weren't working. Hooking into the CMDialogKey event of the form is what I needed!
– David CorneliusMay 20 '13 at 21:51