Making a form "fsStayOnTop"

Forms with the formstyle property set to fsStayOnTop only stay on top when they are the MainForm.

How do you make a non MainForm stay on Top?

(Delphi 3)
greenrcAsked:
Who is Participating?
 
333Connect With a Mentor Commented:
{It is working in Delphi2}

procedure TForm1.Button1Click(Sender: TObject);
begin
{at design time set Form2.FormStyle to fsNormal}  
  form2.show;
  form2.formstyle:=fsStayOnTop;
end;

{Form2 onDeactivate event}
procedure TForm2.FormDeactivate(Sender: TObject);
begin
 BringWindowToTop(Handle);
end;
0
 
interCommented:
Hi,
Please explain the case more. I just make a test, set form2 stay on top while form1 is the main form and form2 stays on top of form1. Do you want your any form to stay on top of other applications?
Igor
0
 
greenrcAuthor Commented:
Igor,

Form1 is the mainform.
When form1 is hidden and form2 shown, form2 does not remain on top of other applications, regardless of the formstyle being set to fsStayOnTop.


0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
ZifNabCommented:
Hi greenrc,

 Does this work? I've got it from somewhere but I don't know anymore from where...

 Form2.SetWindowPos(Handle,
                    HWND_TOPMOST,
                    Left,
                    Top,
                    Width,
                    Height,
                    SWP_NOACTIVATE or SWP_NOMOVE or SWP_NOSIZE);

 Try to put it in some events, like OnShow, ...

Zif.
0
 
greenrcAuthor Commented:
Delphi 3 - Forms do not have a method 'SetWindowPos'
0
 
BoRiSCommented:
greenrc

SetWindowPos is an API call, I think Zif meant pass it like so...

procedure TForm1.FormShow(Sender: TObject);
begin
 SetWindowPos(Handle,
                          HWND_TOPMOST,
                          Left,
                          Top,
                          Width,
                          Height,
                          SWP_NOACTIVATE or SWP_NOMOVE or SWP_NOSIZE);
end;

anyway try this and see if it works...(above)

Later
BoRiS
0
 
greenrcAuthor Commented:
Still does not remain on top of other applications....


0
 
greenrcAuthor Commented:
Adjusted points to 200
0
 
ronit051397Commented:
try SetForegroundWindow or  BringWindowToTop
0
 
greenrcAuthor Commented:
Does not work for forms that are not the main form.
0
 
d003303Commented:
..seems to be a bug in the forms unit.

Slash/d003303
0
 
bomeCommented:
I don't think that it is a real bug - or an intended bug. I always use fsStayOnTop for secondary windows and want that they only stay on top of my main window - not on top of all other windows on the desktop.
Imagine floating toolbars, etc. They always have this behavior.

bome

PS: d003303, you ruined me by giving me the hint to check out experts exchange... I'm hooked ! (I'm the guy in France who extended your drop wrapper)

0
 
d003303Commented:
Yo bome,
nice place here, isn't it ;-)
0
 
ZifNabCommented:
heck, heck, dear bome. I guess everybody here is hooked... we can't stop looking at E-E everyday. Zif. ;-)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.