Solved

Minimize a form on close

Posted on 2004-04-08
4
319 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Need Help Delphi 2010 CheckBox1 Stored value in memo 13 78
update joined tables 2 63
how to change, disabled button color FMX ? 1 50
Delphi: sending SMS on android platform 1 68
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…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

733 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