procedure TForm1.WriteSettings(AUserSettings: TIniFile);
var
Wp: TWindowPlacement;
begin
Assert(AUserSettings <> nil);
if HandleAllocated then begin
// The address of Wp should be used when function is called
Wp.length := SizeOf(TWindowPlacement);
GetWindowPlacement(Handle, @Wp);
AUserSettings.WriteInteger(SektionMainForm, KeyFormLeft,
Wp.rcNormalPosition.Left);
AUserSettings.WriteInteger(SektionMainForm, KeyFormTop,
Wp.rcNormalPosition.Top);
AUserSettings.WriteInteger(SektionMainForm, KeyFormWidth,
Wp.rcNormalPosition.Right - Wp.rcNormalPosition.Left);
AUserSettings.WriteInteger(SektionMainForm, KeyFormHeight,
Wp.rcNormalPosition.Bottom - Wp.rcNormalPosition.Top);
AUserSettings.WriteBool(SektionMainForm, KeyFormMaximized,
WindowState = wsMaximized);
end;
end;
procedure TfrmDatenMonitor.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
inherited;
//*** Save the WindowState in every case
aIniFile.WriteInteger(Name, 'State', Integer(WindowState));
if WindowState = wsNormal then begin
//*** Save Position and Size, too...
aIniFile.WriteInteger(Name, 'Top', Top);
aIniFile.WriteInteger(Name, 'Left', Left);
aIniFile.WriteInteger(Name, 'Height', Height);
aIniFile.WriteInteger(Name, 'Width', Width);
end;
end;
5条答案
按热度按时间ztigrdn81#
使用Windows API函数 GetWindowPlacement(),如下所示:
k97glaaz2#
请尝试使用Form.WindowState属性。通过阅读该属性,可以将其写入ini文件,然后从ini读回以在www.example.com方法中重新设置状态form.show。由于WindowState是枚举类型(TWindowState),因此可能需要将其重新转换为整数。
omtl5h9j3#
Tom的答案应该很好用。下面是一些伪代码来澄清一下:
阅读设置时,首先设置Size和Position。然后读取WindowState并使用类型转换对其赋值:
kdfy810k4#
DelphiDabbler有一些不错的window state components,你只需要在你的表单上放一个,它会在表单销毁时将状态保存到ini文件或注册表中,并在表单创建时加载它。
w7t8yxp55#
更新以显示** Delphi 11**解决方案。
请参阅Embarcadero dockwiki https://docwiki.embarcadero.com/RADStudio/Alexandria/en/Using_TIniFile_and_TMemIniFile
FMX代码: