Página 1 de 1

how to activate the window?

Publicado: Mié May 09, 2018 9:01 pm
por Hurricane
If I minimize Form1 to instantiate and display Form2, the window is displayed but without giving the focus, it is necessary to click.

Original test:

Código: Seleccionar todo

METHOD Button1Click( oSender ) CLASS TForm1   
   ::Minimize()
   with object TForm2():New(self)
      :ShowModal()
   end with   
   ::Restore()
   RETURN Nil
other unsuccessful attempts:

Código: Seleccionar todo

METHOD Button1Click( oSender ) CLASS TForm1   
   with object TForm2():New(self)
      ::Minimize()
      :setFocus() 
      :ShowModal()
   end with   
   ::Restore()
   RETURN Nil
In form2:

Código: Seleccionar todo

METHOD FormInitialize( oSender ) CLASS TForm2
   LogDebug(Application:oActiveForm:className) // TForm1
   ::oEdit1:SetFocus()
RETURN Nil
more information:
1-the onActive event was run
2-the edit displays the cursor blinking (and the form is not active)

Código: Seleccionar todo

METHOD FormActivate( oSender, oCtl ) CLASS TForm2
   LogDebug( 'active' )
   RETURN Nil

Re: how to activate the window?

Publicado: Jue May 10, 2018 9:34 pm
por jfgimenez
Try

Código: Seleccionar todo

SetForegroundWindow( ::Handle )
::SetFocus()

Re: how to activate the window?

Publicado: Vie May 11, 2018 6:58 pm
por Hurricane
The window is activated, but no control receives focus automatically.

As I have to give focus to the first data control (not knowing which), I had to create an xSetFocus only for this form, because in this situation GoFirstControl() also does not help.

Código: Seleccionar todo

   ::minimize()
   with object TFrmAny():New(self)
      ...
      //:GoFirstControl() // Does not work
      :xSetFocus()        // activates the window and the first data control
      :ShowModal()
   end with
   ::restore()
jfgimenez escribió:Try

Código: Seleccionar todo

SetForegroundWindow( ::Handle )
::SetFocus()