| |

VerySource

 Forgot password?
 Register
Search
View: 1073|Reply: 7

How to make a window's close button just hide it when I click it?

[Copy link]

2

Threads

4

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-3-24 09:00:01
| Show all posts |Read mode
As the title, what is the difference between HIDE and CLOSE of a window?
Reply

Use magic Report

2

Threads

7

Posts

8.00

Credits

Newbie

Rank: 1

Credits
8.00

 United States

Post time: 2020-7-5 00:45:01
| Show all posts
Intercept Windows messages and then process them
Reply

Use magic Report

0

Threads

34

Posts

21.00

Credits

Newbie

Rank: 1

Credits
21.00

 China

Post time: 2020-7-5 10:45:01
| Show all posts
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  self.Hide;
  abort;
end;
Reply

Use magic Report

0

Threads

4

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-7-10 23:45:01
| Show all posts
procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
    CanClose := false;
    Form1.Hide;
end;
Reply

Use magic Report

0

Threads

17

Posts

16.00

Credits

Newbie

Rank: 1

Credits
16.00

 China

Post time: 2020-7-11 11:45:02
| Show all posts
action:=canone;
  hide;
Reply

Use magic Report

0

Threads

5

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-7-11 13:30:02
| Show all posts
Create a global variable: CloseTrue:Boolean;

Set a real close button in the program, the event code is
procedure TForm1.btnCloseClick(sender:TObject);
begin
CloseTrue:=True;
Close;
end;
In the closing inquiry event of the form
procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
    CanClose := CloseTrue;
    Form1.Hide;
end;
Reply

Use magic Report

0

Threads

4

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-7-12 10:15:01
| Show all posts
Under normal circumstances, the close of the main window of the program means the termination of the program
And the close of other forms is just hide
If you want to hide when the main form is closed, you can use the one mentioned above
    CanClose := CloseTrue;
    Form1.Hide;
If other forms want to be released when closed, use
    action := caFree;
    freeAndNil(Form1);
Reply

Use magic Report

0

Threads

53

Posts

29.00

Credits

Newbie

Rank: 1

Credits
29.00

 China

Post time: 2020-7-13 15:30:01
| Show all posts
Close is an event and hide is a method. The latter cannot add its own setting function. In fact, the difference between the two is not much. As the upstairs said, the close of the main form is to close the window. If it is another window, hide and close are almost the same. Of course, the parameter Action in the close can also serve the MDI child window,
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list