Mega Code Archive

 
Categories / Delphi / Examples
 

Making a form always visible

How to make a form always visible staying on top of other forms Making a form "always visible" To make a form always visible above other forms either belonging to the same application as well as other applications, we can change the FormStyle property to fsStayOnTop. Later we can switch back to normal by setting FormStyle to fsNormal. However, changing the FormStyle property at runtime isn't recommended. Instead, we should use the Windows API function SetWindowPos, passing it HWND_TOPMOST as the second parameter to activate the effect: procedure TForm1.Button1Click(Sender: TObject); begin SetWindowPos(Handle, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE + SWP_NOSIZE); end; To deactivate this effect, we call SetWindowPos again, this time passing it WND_NOTOPMOST as the second parameter: procedure TForm1.Button2Click(Sender: TObject); begin SetWindowPos(Handle, WND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE + SWP_NOSIZE); end;