![]() |
AW: Fensterposition sowie -größe auf zweitem Monitor speichern und laden
Zitat:
Delphi-Quellcode:
procedure TForm1.FormCreate(Sender: TObject);
begin Position := poDesigned; Left := 2000; Top := 800; end; |
AW: Fensterposition sowie -größe auf zweitem Monitor speichern und laden
Unabhängig von der Anzahl der Monitore verwende ich schon sehr lange die folgenden INIs:
Beim Programmstart:
Delphi-Quellcode:
und wenn Fenster geschlossen werden, speichern der Fensterpositionen:
procedure p_IniRead(AForm : TCustomForm);
// INI Datei einlesen und Fensterpositionen bestimmen var Ini : TIniFile; tmpFormName : string; begin Ini := TIniFile.Create(ChangeFileExt( Application.ExeName, '.INI' ) ); try tmpFormName := AForm.Name; AForm.Top := Ini.ReadInteger(tmpFormName, 'Top', AForm.Top ); AForm.Left := Ini.ReadInteger(tmpFormName, 'Left', AForm.Left ); AForm.Height := Ini.ReadInteger(tmpFormName, 'Height', AForm.Height); AForm.Width := Ini.ReadInteger(tmpFormName, 'Width', AForm.Width); if Ini.ReadBool( tmpFormName, 'InitMax', false ) then AForm.WindowState := wsMaximized else AForm.WindowState := wsNormal; finally Ini.Destroy; end; if Screen.MonitorFromWindow(aForm.Handle, mdNull) = nil then begin // Form is outside of any monitor. Move to center of main monitor aForm.Top := (Screen.Monitors[0].Height - aForm.Height) div 2; aForm.Left := (Screen.Monitors[0].Width - aForm.Width) div 2; end; end;
Delphi-Quellcode:
Und durch die Weitergabe der Form klappt das auch mit beliebigen Fenstern in einem Programm. Und das Handling, wenn mal nur ein Monitor vorhanden ist, ist auch gleich enthalten (wurde aber oben ja auch schon gezeigt).
procedure TFrmMain.p_IniFormPosRead(AForm : TCustomForm);
// Position der Form merken var Ini : TIniFile; tmpFormName : string; begin Ini := TIniFile.Create(ChangeFileExt( Application.ExeName, '.INI' ) ); try tmpFormName := AForm.Name; AForm.Top := Ini.ReadInteger(tmpFormName, 'Top', AForm.Top ); AForm.Left := Ini.ReadInteger(tmpFormName, 'Left', AForm.Left ); AForm.Height := Ini.ReadInteger(tmpFormName, 'Height', AForm.Height); AForm.Width := Ini.ReadInteger(tmpFormName, 'Width', AForm.Width); if Ini.ReadBool( tmpFormName, 'InitMax', false ) then AForm.WindowState := wsMaximized else AForm.WindowState := wsNormal; finally Ini.Destroy; end; Gruß |
Alle Zeitangaben in WEZ +1. Es ist jetzt 07:58 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz