Mega Code Archive

 
Categories / Delphi / Forms
 

Always on top

Title: Always on top Question: Sometimes it's needed to toggle the AlwaysOnTop status of a form at runtime. But the screen flickers if we change the FormStyle property to fsStayOnTop, so we need another approach. Answer: procedure AlwaysOnTop(Form: TForm; OnTop: Boolean); begin if OnTop then SetWindowPos(Form.Handle, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE or SWP_NOSIZE) else SetWindowPos(Form.Handle, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE or SWP_NOSIZE) end; This will not refresh the screen, but after a call to this function you will see that the form will stay on top