?
Solved

Minimize a form on close

Posted on 2004-04-08
4
Medium Priority
?
321 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 26

Accepted Solution

by:
Russell Libby earned 200 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

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…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses
Course of the Month12 days, 17 hours left to enroll

777 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