• Delphi CoolTrayIcon组件的使用


      CoolTrayIcon组件可以实现托盘效果,CoolTrayIcon组件需要在网上进行下载才可以使用,使用起来很简单,基本上不用写代码,但是写少量代码来控制CoolTrayIcon组件实现托盘程序可以增加灵活性,其基本的使用方法可以参照下面的代码:

    unit Unit1;
    
    interface
    
    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, CoolTrayIcon, Menus;
    
    type
      TForm1 = class(TForm)
        CoolTrayIcon1: TCoolTrayIcon;
        PopupMenu1: TPopupMenu;
        N1: TMenuItem;
        N2: TMenuItem;
        procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
        procedure CoolTrayIcon1DblClick(Sender: TObject);
        procedure CoolTrayIcon1MouseDown(Sender: TObject; Button: TMouseButton;
          Shift: TShiftState; X, Y: Integer);
        procedure N1Click(Sender: TObject);
        procedure N2Click(Sender: TObject);
        procedure CoolTrayIcon1MouseMove(Sender: TObject; Shift: TShiftState;
          X, Y: Integer);
        procedure FormCreate(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;
    
    var
      Form1: TForm1;
    
    implementation
    
    {$R *.dfm}
    
    procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
    begin
       CoolTrayIcon1.IconVisible:=True; //窗口关闭时进行查询,此时设置显示托盘图标,隐藏主窗体,不关闭主窗体
       CoolTrayIcon1.HideMainForm;
       Canclose:=False;
    end;
    
    procedure TForm1.CoolTrayIcon1DblClick(Sender: TObject);
    begin
       CoolTrayIcon1.IconVisible:=False; //当双击托盘图标时,显示主窗体,隐藏托盘图标
       CoolTrayIcon1.ShowMainForm;
    end;
    
    procedure TForm1.CoolTrayIcon1MouseDown(Sender: TObject;
      Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
    begin
       If Button=mbRight  then  PopupMenu1.Popup(x,y); //当鼠标右键单击时,弹出菜单出现,当然这个功能也可以通过直接设置CoolTrayIcon组件的PopupMenu属性来实现
       If Button=mbLeft   then  Begin                  //鼠标左键单击时,显示主窗体隐藏托盘
       CoolTrayIcon1.IconVisible:=False;
       CoolTrayIcon1.ShowMainForm;
       End;
    end;
    
    procedure TForm1.N1Click(Sender: TObject);
    begin
       Application.Terminate;   //菜单程序,关闭程序
    end;
    
    procedure TForm1.N2Click(Sender: TObject);
    begin
       CoolTrayIcon1.IconVisible:=False;  //菜单显示主窗体
       CoolTrayIcon1.ShowMainForm;
    end;
    
    procedure TForm1.CoolTrayIcon1MouseMove(Sender: TObject;
      Shift: TShiftState; X, Y: Integer);
    begin
        CoolTrayIcon1.Hint:='程序正在后台运行中'+#13#10+'欢迎使用!!'; //当鼠标在托盘上移动时,显示的提示文本
    end;
    
    procedure TForm1.FormCreate(Sender: TObject);
    begin
       CoolTrayIcon1.IconVisible:=False;//创建窗体时,不显示托盘
    end;
    
    end.
    好的代码像粥一样,都是用时间熬出来的
  • 相关阅读:
    Spring框架——JdbcTemplate(Spring对Jdbc的封装)
    Spring框架——批处理(batch)和事务(Transaction)
    Spring框架——AOP(面向切面编程)详解
    Spring框架——关于IOC容器和注解的36个小实验
    学习新技术的 10 个建议
    解决 PHP Fatal error: Call-time pass-by-reference has been removed
    mysql下float类型使用一些误差详解
    windows 如何查看端口占用情况
    插件机制
    .net/c#常用框架/中间件简介
  • 原文地址:https://www.cnblogs.com/jijm123/p/13441140.html
Copyright © 2020-2023  润新知