Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

fsstayontop question 2

Status
Not open for further replies.

pierrotsc

Programmer
Nov 25, 2007
358
US
I have my main form that has a fsnormal formstyle. When i click a button, it creates a new form that has a formstyle of fsstayontop. This new form when it gets created, creates a small form also that has a fsstayontop formstyle.
The issue i am having is that the last fsstayontop form is not on top of all the forms. It is behind the form that created it.
Am i doing something wrong?
Thanks.
P.
 
There are actually lots of issues that can interfere how stayontop works. Such as if you display a message (via MessageDlg) then that message will show up behind your form, which makes your message hard to find.

I've found that it's best to be able to turn on and off the stayontop property. To do so:

Code:
TForm1 = class(TForm)
   ...
   procedure FormPaint(Sender: TObject);//add onpaint handler
 private
   procedure Make_StayOnTop;//add this to private section
   ...
end;

procedure TForm1.Make_StayOnTop;
begin
   SetWindowPos(Self.Handle, HWND_TOPMOST, 0,0,0,0, SWP_NOMOVE or SWP_NOACTIVATE or SWP_NOSIZE);
   OnPaint := FormPaint;
end; 

procedure TForm1.FormPaint(Sender: TObject);
begin
   SetZOrder(True);
end;

Then when you need to turn on stayontop like in FormCreate:

Code:
FormStyle := fsStayOnTop; //set to stayontop
OnPaint := FormPaint; //Connect FormPaint Handler

and to turn off stayontop like when your second form is created

Code:
FormStyle := fsNormal; //set to normal
OnPaint := nil; //disconnect FormPaint Handler
 
I see...This look like a very good idea.
Now when i create a new form , should i have that code in the new formcreate code?
Make_StayOnTop;
FormStyle := fsStayOnTop; //set to stayontop
OnPaint := FormPaint; //Connect FormPaint Handler

if i want to keep adding forms on top of each other, do i need to turn off the fsstayontop for the form below the one i just created?

Thanks.
P
 
Actually, in the Formcreate, just call make_Stayontop. I shouldn't have used the formcreate as an example in my previous post.

From there, you determine when you want to turn off and back on by setting the formstyle property and (dis)connecting the onpaint accordingly.

So if you want to use a MessageDlg or a new form, then disconnect just before and reconnect just after.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top