Board index » cppbuilder » How can child form get focus & key down event?

How can child form get focus & key down event?

Hi,

  I write a simple program. There are a Main Form & a Child Form. I put 2 Panels on Main Form and a Button on Panel1. The design properties of these 2 Panels are:
Panel1->Align = alTop;
Panel2->Align = alClient;
MainForm->ActiveControl = Button1;

  I create a Child Form on MainForm->Show() as follow:
void __fastcall TMainForm::FormShow(TObject *Sender)
{
   ChildForm = new TChildForm(Application);
   ChildForm->Name = "ChildForm";
   ChildForm->Parent = Panel2;
   ChildForm->Show();

Quote
}

I write OnKeyDown event function for MainForm & ChildForm. When I press left key, the KeyDown event doesn't occur. My problems are:
1.How can I set ChildForm active?
2.How can I get ChildForm's KeyDown event?

Thanks for your help.

Best Regards

eric

 

Re:How can child form get focus & key down event?


Not sure if this will help or not, but I recently had problems related to
setting a form's Parent to a Panel.  You can try using the Win32 API
function SetParent() instead of setting the Parent property, as they work a
little differently on the window:

    ChildForm = new TChildForm(Application);
    ::SetParent(ChildForm->Handle, Panel2->Handle);
    ChildForm->Show();

Gambit

Quote
eric Kao <eric_...@tri.com.tw> wrote in message news:3b4d8399$1_2@dnews...
>   I create a Child Form on MainForm->Show() as follow:
> void __fastcall TMainForm::FormShow(TObject *Sender)
> {
>    ChildForm = new TChildForm(Application);
>    ChildForm->Name = "ChildForm";
>    ChildForm->Parent = Panel2;
>    ChildForm->Show();
> }

Re:How can child form get focus & key down event?


Quote
"Remy Lebeau" <gambi...@gte.net> wrote:
>Not sure if this will help or not, but I recently had problems related to
>setting a form's Parent to a Panel.  You can try using the Win32 API
>function SetParent() instead of setting the Parent property, as they work a
>little differently on the window:

>    ChildForm = new TChildForm(Application);
>    ::SetParent(ChildForm->Handle, Panel2->Handle);
>    ChildForm->Show();

>Gambit

Thanks for your info. It solves part of my problem. I add a menu on MainForm now. Once I pressing ALT+Key to shift focus to menu. The ChildForm can't get focus via mouse click. How can I do?

Best Regards

Eric

Other Threads