Delphi Tips&Tricks News   Tips   .NET Software   VCL Software   Search   Contacts
Ultimate Pack - special offer!

Ultimate Pack  hot!
Image Editor  new!
Runtime Fusion
Form Designer
Object Inspector
Print Suite Pro
Commented Image
Delphi Toys
WinDowse
Delphi Bonus
TMS Scripter Studio
Form Designer VB
Form Designer .NET

...get more...
for Delphi.NET, C#, VB.NET
for Delphi VCL, BCB 3-6

WinAPI Online
Unix Manual Pages
MegaDetailed.NET
in3steps.com
cdtrrracks.com new!

Blogspot  greatis.blogspot.com

Restore window to its last state - Forms - Tips & Tricks - Greatis Delphi Pages

You can store the main parameters of your form in Registry. Resave them, when you close form, and you can restore them, if you create form again.


uses Registry;

procedure TForm1.FormDestroy(Sender: TObject);
begin
  with TRegistry.Create do
  begin
   RootKey:=HKEY_LOCAL_MACHINE;
   if OpenKey('Greatis Software\Example\Form', True) then
   begin
     WriteInteger('Left', Form1.Left);
     WriteInteger('Top',  Form1.Top);
     WriteInteger('Width', Form1.Width);
     WriteInteger('Height', Form1.Height);
     case WindowState of
       wsMaximized: WriteInteger('State', 1);
       wsMinimized: WriteInteger('State', 2);
       wsNormal   : WriteInteger('State', 3);
     end;
   end
   else
     MessageDlg('Registry reading error', mtError, [mbOk], 0);
   CloseKey;
  end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  with TRegistry.Create do
  begin
    RootKey:=HKEY_LOCAL_MACHINE;
    if OpenKey('Greatis Software\Example\Form', False) then
    try
      Form1.Left:=ReadInteger('Left');
      Form1.Top:=ReadInteger('Top');
      Form1.Width:=ReadInteger('Width');
      Form1.Height:=ReadInteger('Height');
     case ReadInteger('State') of
       1: Form1.WindowState:=wsMaximized;
       2: Form1.WindowState:=wsMinimized;
       3: Form1.WindowState:=wsNormal;
     end;
    except
      MessageDlg('Can not go to handle', mtError, [mbOk], 0);
    end
    else
      MessageDlg('Registry reading error', mtError, [mbOk], 0);
    CloseKey;
  end;
end;
Related chapters
System
Registry

Related topics
Detect windows version
Detect font (Small or Large) is in use
Use registry instead of *.ini file

For more
Delphi Help

Download source