Recent

Author Topic: How can I set focus on a Form  (Read 7467 times)

clauslack

  • Sr. Member
  • ****
  • Posts: 275
How can I set focus on a Form
« on: November 05, 2009, 03:21:06 pm »
HI, I need help from the comunity.

I have a principal form (Form1), and this, I can open many form with Form.ShowModal(Form2, Form3, etc)

I have a Timer1 in the principal form(Form1), that show a message box when arrive new messages for the user.

All works fine when the application is maximized.
But when application is minimized in a Form2 or Form3 and arrives a new message with ShowMessage, the calling form receives the focus (Form1) and then I can't access to Form2, because Form1 is disabled...

A workarround is put the ShowMessage in all Forms(Form2,Form3), but is not the ideal.

Any Idea?

Thanks

« Last Edit: November 05, 2009, 04:06:55 pm by clauslack »

Leledumbo

  • Hero Member
  • *****
  • Posts: 8266
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: How can I set focus on a Form
« Reply #1 on: November 06, 2009, 11:48:59 am »
Set WindowState to wsNormal / wsMaximize before calling ShowMessage.

clauslack

  • Sr. Member
  • ****
  • Posts: 275
Re: How can I set focus on a Form
« Reply #2 on: November 06, 2009, 02:03:30 pm »
I do it that, but not work, because ...

- Form1 open Form2 in ShowModal, so Form1 is disabled, Form2 has
the focus.
- Minimize Form2. (this minimize all the application)

- The Form1.Timer1 (every minute if there new message) display the ShowMessage.
- Close ShowMessage with OK.
- The ShowMessage give the focus to the calling form (Form1), but
Form1 is disabled....
- Form2 is behind Form1 (both maximized) and I can not choose Form2.

That is the problem.

I have two workarround.
- The Form1.Timer Call a Form2.ShowMessage, Form3.ShowMessage,
FormN.ShowMessage so the ShowMessage give the focus to the calling form (Form2, Form3,etc) I have 30 forms, and more are added

- Form1.Timer call an external executable with ShowMessage and ParamStr(1) for display the message. (the best solution for now)

Summary: ShowMessage give the focus to the calling form.

Thanks anyway



zeljko

  • Hero Member
  • *****
  • Posts: 1147
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: How can I set focus on a Form
« Reply #3 on: November 06, 2009, 02:36:13 pm »
What widgetset / OS ?

clauslack

  • Sr. Member
  • ****
  • Posts: 275
Re: How can I set focus on a Form
« Reply #4 on: November 06, 2009, 03:04:42 pm »
Lazarus 0.9.27/0.9.29 fpc 2.3.1/2.5.1 Windows 2000/XP.

Under Delphi I can see the Taks Bar of Form2 minimized, over Form1 disabled.



 

TinyPortal © 2005-2018