在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
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.
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论