Recent

Author Topic: Main Window bring to front?  (Read 10313 times)

IPguy

  • Sr. Member
  • ****
  • Posts: 385
Main Window bring to front?
« on: October 29, 2011, 05:21:10 pm »
Have one main window with about 8 child windows.  Each of the child windows are opened with showmodal.
When I close the child window, I expect the main window to receive focus again and be the top window on the screen.

However, that is not happening when I have other applications on the screen.  When I close the child window, the main window is usually "buried" under the Laz editor windows, file manager, web browser, etc...

How can I ensure that the main window receives the focus upon child window hide/close?
fMainForm.BringToFront did not do that, nor did fMainForm.Focused;   

edited:  sorry -should have given the details:
0.9.31-32432-2.5.1-Win32-Vista
« Last Edit: October 29, 2011, 05:43:18 pm by IPguy »

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: Main Window bring to front?
« Reply #1 on: October 29, 2011, 05:34:13 pm »
I have not tried it, but try SetFocus.

IPguy

  • Sr. Member
  • ****
  • Posts: 385
Re: Main Window bring to front?
« Reply #2 on: October 29, 2011, 05:42:08 pm »
Thanks typo, but no luck with SetFocus.
The main window remained buried.

And it is odd.  With the child window up, the main window is right under it.
When I exit the child, the main window moves to the back of some (all?) other windows.

Code: [Select]
procedure TfReg.FormClose(Sender: TObject; var CloseAction: TCloseAction);
begin
  fReg.Hide;
  fRIMMain.SetFocus;
end;               
         

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: Main Window bring to front?
« Reply #3 on: October 29, 2011, 06:27:25 pm »
AFAIK, you should not use ShowModal with more than a single form at a time.
« Last Edit: October 29, 2011, 06:33:07 pm by typo »

IPguy

  • Sr. Member
  • ****
  • Posts: 385
Re: Main Window bring to front?
« Reply #4 on: October 30, 2011, 02:25:09 am »
typo, if I understand your point, that was poor wording on my part.
While I have several modal windows within my program, only one at a time is visible. 

I had assumed that multiple modal wndows within one app are acceptable, but that only one modal windows at a time should be visible.

I fixed the issue, but I have more questions which I have to research.

Summary: I changed the .Hide to a .Close.

Code: [Select]
procedure TfReg.FormClose(Sender: TObject; var CloseAction: TCloseAction);
begin
  fReg.Close;
end;     
               

I did not have an onHide event

« Last Edit: October 30, 2011, 02:27:03 am by IPguy »

gajahbengkak

  • New Member
  • *
  • Posts: 13
  • this is me, mine, myself
    • Catatan Si Arief
Re: Main Window bring to front?
« Reply #5 on: October 30, 2011, 03:38:59 am »
it's ok to use many modal windows at one time, i have to do that when i open many dialogs.

don't call close from close event it will recursive.

method FormClose(Sender: TObject; var CloseAction: TCloseAction) is called when you close a form, with the form as Sender and default CloseAction is caHide means the form will be hidden or in the case of main form it will close the application.

may be you need to call the BringToFront after you call the ShowModal not in the form close event cause the modal form is not closed yet.

User137

  • Hero Member
  • *****
  • Posts: 1791
    • Nxpascal home
Re: Main Window bring to front?
« Reply #6 on: October 30, 2011, 04:34:15 am »
Maybe Application.Activate?

Oh these
Code: [Select]
procedure TfReg.FormClose(Sender: TObject; var CloseAction: TCloseAction);
begin
  // fReg.Hide;  // Why would you hide form that will be hidden in the Close anyway?
  // fRIMMain.SetFocus; // Don't refer to caller form from child form

{ You might have this in the fRIMMain
  fReg.ShowModal;
  //SetFocus; // Is this really necessary anyway?
}
end;
« Last Edit: October 30, 2011, 04:38:15 am by User137 »

IPguy

  • Sr. Member
  • ****
  • Posts: 385
Re: Main Window bring to front?
« Reply #7 on: November 01, 2011, 02:12:05 pm »
It appears that there are two types of objects that I have to deal with:
1) those that only raise events (ie: buttons, etc...)
2) those that raise events AND do their own actions. (ie: windows close)

An example of #2 is the windows close ("X"), where the object itself performs an action in addition to raising the onClose event.

I had assumed if I received an onClose event, I had do a form.close.
That confusion has been cleared up and the redundant .close's have been removed.

Thanks all, for the clarification and the education.

User137

  • Hero Member
  • *****
  • Posts: 1791
    • Nxpascal home
Re: Main Window bring to front?
« Reply #8 on: November 01, 2011, 03:02:42 pm »
They are actually not at all about objects, but window messages by operating system. WM_something for example.
You can manually call formX.Close; by any TButton or anything at all which automatically calls onClose event in addition to closing form. There is much similar automatic events with many components.
For example calling ScrollBar.Position:=10; would also call TScrollBar.onChange event, and the same with TEdit's .text property.
« Last Edit: November 01, 2011, 03:05:39 pm by User137 »

avra

  • Hero Member
  • *****
  • Posts: 2514
    • Additional info
Re: Main Window bring to front?
« Reply #9 on: November 02, 2011, 11:03:03 am »
TApplication also has BringToFront:

BringToFront - Use the selected widget set's method to bring the application's form(s) to the front
ct2laz - Conversion between Lazarus and CodeTyphon
bithelpers - Bit manipulation for standard types
pasettimino - Siemens S7 PLC lib

Awesome Programmer

  • Sr. Member
  • ****
  • Posts: 451
  • Programming is FUN only when it works :)
    • Cool Technology
Re: Main Window bring to front?
« Reply #10 on: November 19, 2018, 09:02:15 pm »
avra

I am in the same situation. I am trying to bring form to the front or send a form to the back using SendtoBack and BringToFront, but it won't work.

HeavyUser

  • Sr. Member
  • ****
  • Posts: 397
Re: Main Window bring to front?
« Reply #11 on: November 19, 2018, 09:16:11 pm »
avra

I am in the same situation. I am trying to bring form to the front or send a form to the back using SendtoBack and BringToFront, but it won't work.
windows only

Code: Pascal  [Select][+][-]
  1.   SetWindowPos(form1.handle, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE or SWP_NOSIZE);
  2.  

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: Main Window bring to front?
« Reply #12 on: November 19, 2018, 11:26:22 pm »
I am in the same situation. I am trying to bring form to the front or send a form to the back using SendtoBack and BringToFront, but it won't work.

When talking about TControl descendants (like TForm), BringToFront and SendToBack apply only in reference to other controls (in this case other forms) in the same application. The LCL documentation expresses it as:

Quote
TControl.BringToFront
    Bring the control in front of all sibling controls.

TControl.SendToBack
    Moves all sibling controls in front of this control.

Note the reference to sibling controls; if the application is not the active one or there are other system-modal windows then the control/form will remain behind it because the application itself is behind the currently active one.
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

CCRDude

  • Hero Member
  • *****
  • Posts: 596
Re: Main Window bring to front?
« Reply #13 on: November 20, 2018, 08:56:53 am »
Code: [Select]
On Windows, I successfully use [url=https://www.swissdelphicenter.ch/de/showcode.php?id=261]this code which covers a bunch of scenarios (I use it when another instance of my application is run, which just passes it's parameters to the existing instance, which needs to process them and come to the foreground).

Nothing I use on other platforms yet.

Regarding BringToFront/SendToBack: on Cocoa, these tend to make controls invisible in the current trunk in my experience.

 

TinyPortal © 2005-2018