I have an application which consists of a form with FormStyle declared as "fsStayOnTop", so that it always is shown on top of all other windows. Now I would like to temporarily show another form where the user can set some settings. That form should also be shown on top, so I change the FormStyle property of the main form to "fsNormal" and the FormStyle of the form I want to show to "fsStayOnTop". When the temporary form closes the main form gets "fsStayOnTop" again.
我有一个应用程序,它包含一个FormStyle声明为“fsStayOnTop”的表单,因此它总是显示在所有其他窗口的顶部。现在我想暂时显示另一个用户可以设置一些设置的表单。该表单也应显示在顶部,因此我将主窗体的FormStyle属性更改为“fsNormal”,并将我想要显示的窗体的FormStyle更改为“fsStayOnTop”。当临时表单关闭时,主表单再次获得“fsStayOnTop”。
Now the settings form stays on top, but only until I activate it by a mouse click inside the form. When I click on another window after that, the clicked form is on top and the defined FormStyle seems to have no effect anymore. Can anyone help me with that?
现在设置表单保持在顶部,但只有在我通过鼠标单击表单内部激活它之前。当我在此之后单击另一个窗口时,单击的表单位于顶部,并且定义的FormStyle似乎不再有效。任何人都可以帮助我吗?
Here's my FormShow and FormClose mehtod:
这是我的FormShow和FormClose mehtod:
procedure TForm3.FormClose(Sender: TObject; var Action: TCloseAction);
begin
ScaleOpen := false;
SetForegroundWindow(TempHandle);
Form1.FormStyle := fsStayOnTop;
end;
procedure TForm3.FormShow(Sender: TObject);
begin
TempHandle := GetForegroundWindow;
OldScaleM := Form1.GetScale;
SaveChanges := False;
ScaleOpen := true;
Form1.FormStyle := fsNormal;
Form3.FormStyle := fsStayOnTop;
end;
1 个解决方案
#1
You can set a form to the "always on top" state using this code:
您可以使用以下代码将表单设置为“always on top”状态:
SetWindowPos(Handle, HWND_TOPMOST, 0, 0, 0, 0,
SWP_NoMove or SWP_NoSize);
You go back to normal mode with this code:
您可以使用以下代码返回正常模式:
SetWindowPos(Handle, HWND_NOTOPMOST, 0, 0, 0, 0,
SWP_NoMove or SWP_NoSize);
To try it, just drop two buttons on your form and associate the above code to their respective OnClick handlers.
要尝试它,只需在表单上放下两个按钮,并将上面的代码与各自的OnClick处理程序相关联。
#1
You can set a form to the "always on top" state using this code:
您可以使用以下代码将表单设置为“always on top”状态:
SetWindowPos(Handle, HWND_TOPMOST, 0, 0, 0, 0,
SWP_NoMove or SWP_NoSize);
You go back to normal mode with this code:
您可以使用以下代码返回正常模式:
SetWindowPos(Handle, HWND_NOTOPMOST, 0, 0, 0, 0,
SWP_NoMove or SWP_NoSize);
To try it, just drop two buttons on your form and associate the above code to their respective OnClick handlers.
要尝试它,只需在表单上放下两个按钮,并将上面的代码与各自的OnClick处理程序相关联。