Solved

Minimize a form on close

Posted on 2004-04-08
4
318 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
ID: 10789301

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
ID: 10789381
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
ID: 10789410
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
ID: 10791233
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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

813 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

15 Experts available now in Live!

Get 1:1 Help Now