In the middle layer, the middle layer often does not need to click Close when closed, but minimized to the tray. Therefore, the Close button function is deliberately hidden.
1) Hide Exit Function with Popmenu exit menu instead
1. Add Popmenu Exit menu, bind to form
2. Increase the variable control whether really exit B_isclose;//true exit False do not exit
[Delphi]View PlainCopy
- B_isclose:boolean; //true exit False do not exit
3. Initialize B_isclose set to False in Formcreate or Formshow events
[Delphi]View PlainCopy
- Procedure TForm1. Formshow (Sender:tobject);
- Begin
- B_isclose:=false;
- End
4.PopMenu Increase Exit Event
[Delphi]View PlainCopy
- Procedure TForm1Pmexitclick (sender:tobject);
- Begin
- B_isclose: = true; Set to True Exit
- Close; //Call system Exit Event response function Formclose
- End
5. The exit is based on whether the actual exit to do the processing
[Delphi]View PlainCopy
- Procedure TForm1. Formclose (Sender:tobject; var action:tcloseaction);
- Begin
- if B_isclose Then
- begin
- Action: = Cafree; //Real exit
- End
- Else
- begin
- Action: = Canone; //Modify event type does not exit
- end;
- End
2) minimized to pallet
Modify the Formclose event to add a statement:
[Delphi]View PlainCopy
- Application. Minimize; //Minimized applications
As follows:
[Delphi]View PlainCopy
- Procedure TForm1. Formclose (Sender:tobject; var action:tcloseaction);
- Begin
- if B_isclose Then
- begin
- Action: = Cafree; //Real exit
- End
- Else
- begin
- Action: = Canone; //Modify event type does not exit
- Application. Minimize; //Minimized applications
- end;
- End
3) Add right-click popup menu in Tray
1. Install drag and drop add a third-party control Trztrayicon to the interface, named:
[Delphi]View PlainCopy
- Rztrayicon1:trztrayicon;
2. Modify the Formclose event to add a statement:
[Delphi]View PlainCopy
- RzTrayIcon1. PopupMenu: = Pmfrmmenu; //Bind right bottom corner popmenu
The end result is as follows:
[Delphi]View PlainCopy
- Procedure TForm1. Formclose (Sender:tobject; var action:tcloseaction);
- Begin
- if B_isclose Then
- begin
- Action: = Cafree; //Real exit
- End
- Else
- begin
- Action: = Canone; //Modify event type does not exit
- Application. Minimize; //Minimized applications
- RzTrayIcon1. PopupMenu: = Pmfrmmenu; //Bind right bottom corner popmenu
- end;
- End
Delphi minimized program to taskbar tray Add right button popmenu