Board index » cppbuilder » Show a Form and Set the Focus to an Edit-Field

Show a Form and Set the Focus to an Edit-Field

Hello!

In my Application there are several Forms. When the programm shows one of
these Forms, I want
to set the Focus to an Edit-Field

(In main cpp-file: )
  Form_Bla->ShowModal();
(In Form_Bla-cpp-file:
void __fastcall TForm_Bla::FormShow(TObject *Sender)
{
  Edit1->SetFocus();

Quote
}

For this I get a MessageBox (when the programm already runs) saying that an
inactive oder invisible window can't get the focus.

What can I do?

Using the "on activate"-event causes the same problem..

Mathias

 

Re:Show a Form and Set the Focus to an Edit-Field


Set the tab order of the form so that Edit1 is the top of the tab order...it
will
then automatically have the focus...

you could have a timer on the form...that disables it self when first time
timer event is called that sets the focus..
(not elegant way..but works)

Re:Show a Form and Set the Focus to an Edit-Field


Quote
Mathias Michaelis wrote:
> void __fastcall TForm_Bla::FormShow(TObject *Sender)
> {

    // was it visible at designtime ?
    Edit1->Visble=TRUE;

Quote
>   Edit1->SetFocus();
> }

> For this I get a MessageBox (when the programm already runs) saying that an
> inactive oder invisible window can't get the focus.

Does this help ?

Hans.

Re:Show a Form and Set the Focus to an Edit-Field


Hi,

Your   form  has  an  ActiveControl  property.  Just  set  it  at
design-time to Edit1.

Good luck!

Re:Show a Form and Set the Focus to an Edit-Field


He, Thanks!
It works and it is nice code.
:)
Mathias

Other Threads