如何在托盘图标实现漂亮的菜单

[入库:2005年8月18日] [更新:2007年3月25日]

本文简介:选择自 gamaster 的 blog

  今日看到一个帖子问:如何在托盘图标实现象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上你可以作的事情就太多了。

  如果你有更好的方法或思路,欢迎讨论:qq:56059327,msn:kermin@hotmail.com.
  谢谢!

本文关键:如何在托盘图标实现漂亮的菜单
  相关方案
Google
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top