Search code examples
delphivcl

Best way to Hide and Restore an Application


I would like to hide my entire Application and then later restore it back to the state it was (Kinda like minimize to Tray). This includes all opened forms and an included Modal Form. It should also hide each form's taskbar visibility. I can hide the MainForm, but what about the other forms and the modal form? What would be the easiest way to hide dynamically all forms and restore them back to the state how they were?


Solution

  • Call Application.Minimize and Application.Restore to perform these actions.

    To remove a form from the taskbar, hide it. Assuming that you have Application.MainFormOnTaskbar set to True, and only the main form associated with the taskbar, you can use Application.MainForm.Visible := False. Reverse this when you call Application.Restore.

    So, in summary, to go dark:

    Application.Minimize;
    Application.MainForm.Visible := False;
    

    And to reappear:

    Application.MainForm.Visible := True;
    Application.Restore;
    

    If you have more than one form associated with the taskbar, you'd need to hide those forms too to remove the button from the task bar.