Delphi minimized program to taskbar tray Add right button popmenu

Source: Internet
Author: User

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
    1. B_isclose:boolean; //true exit False do not exit

3. Initialize B_isclose set to False in Formcreate or Formshow events

[Delphi]View PlainCopy
    1. Procedure TForm1.  Formshow (Sender:tobject);
    2. Begin
    3. B_isclose:=false;
    4. End


4.PopMenu Increase Exit Event

[Delphi]View PlainCopy
    1. Procedure TForm1Pmexitclick (sender:tobject);
    2. Begin
    3. B_isclose: = true; Set to True Exit
    4. Close; //Call system Exit Event response function Formclose
    5. End


5. The exit is based on whether the actual exit to do the processing

[Delphi]View PlainCopy
  1. Procedure TForm1. Formclose (Sender:tobject;  var action:tcloseaction);
  2. Begin
  3. if B_isclose Then
  4. begin
  5. Action: = Cafree; //Real exit
  6. End
  7. Else
  8. begin
  9. Action: = Canone; //Modify event type does not exit
  10. end;
  11. End


2) minimized to pallet

Modify the Formclose event to add a statement:

[Delphi]View PlainCopy
    1. Application. Minimize; //Minimized applications

As follows:

[Delphi]View PlainCopy
  1. Procedure TForm1. Formclose (Sender:tobject;  var action:tcloseaction);
  2. Begin
  3. if B_isclose Then
  4. begin
  5. Action: = Cafree; //Real exit
  6. End
  7. Else
  8. begin
  9. Action: = Canone; //Modify event type does not exit
  10. Application. Minimize; //Minimized applications
  11. end;
  12. 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
    1. Rztrayicon1:trztrayicon;

2. Modify the Formclose event to add a statement:

[Delphi]View PlainCopy
    1. RzTrayIcon1. PopupMenu: = Pmfrmmenu; //Bind right bottom corner popmenu

The end result is as follows:

[Delphi]View PlainCopy
    1. Procedure TForm1. Formclose (Sender:tobject;  var action:tcloseaction);
    2. Begin
    3. if B_isclose Then
    4. begin
    5. Action: = Cafree; //Real exit
    6. End
    7. Else
    8. begin
    9. Action: = Canone; //Modify event type does not exit
    10. Application. Minimize; //Minimized applications
    11. RzTrayIcon1. PopupMenu: = Pmfrmmenu; //Bind right bottom corner popmenu
    12. end;
    13. End

Delphi minimized program to taskbar tray Add right button popmenu

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.