Delphi Tips&Tricks News   Tips   .NET Software   VCL Software   Search   Contacts
Ultimate Pack Special Offer!


Share this page

Follow us
LinkedIn Blogspot Twitter Facebook

Related products
Ultimate Pack  hot!
iGrid Plotter  new!
Image Editor
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
Print Suite .NET
Gradient Controls .NET  new!

Related links
Win32.hlp online version
MegaDetailed.NET
Delphi to C#

Special
Free Software Promotion
Offers for Resellers

Hobby projects
cdtrrracks.com
books.storrre.com
in3steps.com
sovietphillumeny.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