Solved

Minimize a form on close

Posted on 2004-04-08
4
315 Views
Last Modified: 2010-04-05
Looking for a function or procedure that will minimize my app when I click on the close button instead of closing it.
0
Comment
Question by:voodoo22
  • 2
  • 2
4 Comments
 
LVL 26

Accepted Solution

by:
Russell Libby earned 50 total points
Comment Utility

Pick up the OnCloseQuery and handle the close there, eg:

procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin

  CanClose:=False;
  Application.Minimize;

end;


And of course, you will need to be able to actually "close/terminate" the application at some point, so using either the following

procedure TForm1.Button1Click(Sender: TObject);
begin

  PostQuitMessage(0);

end;

Or

Application.Terminate

can be used to close the app. Really comes down to catching the WM_CLOSE message and overriding the base functionality.

Regards,
Russell

0
 

Author Comment

by:voodoo22
Comment Utility
Oops I accepted your answer aiil to early... I tried adding the above procedure to my form and then added this under it but it's not working...

procedure TForm1.Button1Click(Sender: TObject);
begin
  If Checkbox1.Checked then
    FormCLoseQuery(Application,False);
  else
    Application.Terminate;
end;
0
 

Author Comment

by:voodoo22
Comment Utility
Ok now I see what you are doing but it will not work for me.

What I need is a function that I can use in for the buttons OnClick Event. As you can prob guess from my BAD code above what I am trying to do is give the user the option to minimize the form when the [X] button is pressed or to close it like normal and the way you have it I can't really do that from a button click.
0
 
LVL 26

Expert Comment

by:Russell Libby
Comment Utility
What I posted will work for you, but not the way you have coded it. (You also should mention these things in the initial question).

procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
 
  // If checkbox is marked, just minimize the form
  if Checkbox1.Checked then
  begin
    CanClose:=False;
    Application.Minimize;
  end
  else
    CanClose:=True;

end;

procedure TForm1.Button1Click(Sender: TObject);
begin

  If Checkbox1.Checked then
    Close
  else
    PostQuitMessage(0)

end;

------------
Russell
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now