cyberfan's blog

正其谊不谋其利,明其道不计其功

  IT博客 :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  15 随笔 :: 489 文章 :: 44 评论 :: 0 Trackbacks
今日看到一个帖子问:如何在托盘图标实现象window开始菜单中菜单左侧的图片效果。于是自己动手做了一个。
我的思路是不用菜单,用窗体来实现(我想不仅是delphi其他编程语言应该一样可以)。
例子中我用到了一个第三方控件:Trayicon用来显示动态托盘图标(下载地址:http://2ccc.com/article.asp?articleid=1985)。请看我如下步骤:
1.新建立一个project,同时建立两个窗体Form1和iconform。其中第二个用来显示托盘图标菜单。
2.各放置一个Trayicon、imagelist和Applicationevents控件于Form1上。
3.加入合适的图标到imagelist,然后在trayicon的属性编辑器中的icon项关联imagelist。(如果你加入了多个图标,你可以把trayicon的animate设置为true,可以看见动态图标,trayicon控件包里有DEMO)
4.将trayicon的popupmenuon属性设置为imnone;visible设置为true。
5.在trayicon的mouseup事件中写:
var
APoint: TPoint;
begin
GetCursorPos(APoint);
if (Screen.ActiveForm <> nil) and (Screen.ActiveForm.Handle <> 0) then
SetForegroundWindow(Screen.ActiveForm.Handle);
if iconform.Width + apoint.X <= screen.Width then
iconform.left:=APoint.X
else
iconform.Left:=APoint.X - FORM2.Width;

iconform.Top:=apoint.Y - FORM2.Height;
iconform.Show;
end;
6.在applicationevents的deactivate事件中写:
iconform.Close;
7.在iconform上放置两个标签label_restore,label_exit
8.在iconform的deactivate事件中写: close;
9.在label_restore的click事件中写: form1.trayicon1.Restore;
在label_exit的click事件中写: Application.Terminate;
10.至此,编程工作已经完成,运行后点击托盘图标看看效果如何。你可以在iconform上作你想作的事情,不用说图片,在form上你可以作的事情就太多了。
posted on 2005-08-12 15:40 cyberfan 阅读(286) 评论(0)  编辑 收藏 引用 所属分类: delphi
只有注册用户登录后才能发表评论。