Board index » delphi » Setting focus to MDI children???

Setting focus to MDI children???

Hi all,

Here's my problem.

I want the app to set focus to the current child form whenever focus
is in the parent and the user presses F12.  

Here's a code snippet:  (from MainForm KeyPress event)

     if key = VK_F12 then
     begin
        showmessage('F12 pressed...');
        Mainform.ActiveMDIChild.setfocus;
     end;

This works!!!  However, if I remove the ShowMessage line, it DOES NOT
set focus.  So, I figured I'd try an API call:

     if key = VK_F12 then
     begin
        if SetActiveWindow(MainForm.MDIChildren[0].Handle) <> 0 then
           showmessage('Set focus to MDI chld...')
        else
           Showmessage('SetActiveWindow failed!...');
     end;

This triggers on press of F12, shows me a message "Set focus to MDI
child...", but, again, DOES NOT set the focus!!!

Does anyone have any ideas??  Am I missing something obvious??

Thanks,  (pls reply via email)

Greg Wareham
Pangaea Systems Inc
gware...@pangaea.ca

 

Re:Setting focus to MDI children???


Quote
gware...@pangaea.ca (Greg Wareham) wrote:
>Hi all,
>Here's my problem.
>I want the app to set focus to the current child form whenever focus
>is in the parent and the user presses F12.  
>Here's a code snippet:  (from MainForm KeyPress event)
>     if key = VK_F12 then
>     begin
>        showmessage('F12 pressed...');
>        Mainform.ActiveMDIChild.setfocus;
>     end;
>This works!!!  However, if I remove the ShowMessage line, it DOES NOT
>set focus.  So, I figured I'd try an API call:
>     if key = VK_F12 then
>     begin
>        if SetActiveWindow(MainForm.MDIChildren[0].Handle) <> 0 then
>           showmessage('Set focus to MDI chld...')
>        else
>           Showmessage('SetActiveWindow failed!...');
>     end;
>This triggers on press of F12, shows me a message "Set focus to MDI
>child...", but, again, DOES NOT set the focus!!!
>Does anyone have any ideas??  Am I missing something obvious??
>Thanks,  (pls reply via email)
>Greg Wareham
>Pangaea Systems Inc
>gware...@pangaea.ca

This should work:

     if key = VK_F12 then
     begin
        Mainform.FocusControl(nil);
        Mainform.ActiveMDIChild.setfocus;
     end;

Hope this helps.

David R. Michael
davi...@busprod.com
www.busprod.com/davidrm

Other Threads