本溪县新闻,miankongqu,要过好日子演员表
我在terminalmacs中添加了托盘菜单,最终实现的托盘菜单效果:
【step 1】在已创建的wpf项目中,添加handycontrol库,并安装:
你问我为什么要使用hc控件库?先看demo效果:
常用的托盘效果应该都能满足了吧?而实现这些效果,我们自己要码的代码真的不多,因为hc已经封装了,我们直接使用即可。
【step 2】在窗体中添加handycontrol命名空间
xmlns:hc="https://handyorg.github.io/handycontrol"
【step 3】声明托盘菜单关键的19行代码
<hc:notifyicon x:name="notifyiconcontextcontent" text="{markup:i18n {x:static i18nresources:language.apptitle}}" visibility="visible" icon="/images/logo.ico"> <hc:notifyicon.contextmenu> <contextmenu> <menuitem command="hc:controlcommands.pushmainwindow2top" header="{markup:i18n {x:static i18nresources:language.pushmainwindow2top}}"/> <menuitem command="hc:controlcommands.shutdownapp" header="{markup:i18n {x:static i18nresources:language.exit}}"/> </contextmenu> </hc:notifyicon.contextmenu> <hc:interaction.triggers> <hc:eventtrigger eventname="click"> <hc:eventtocommand command="hc:controlcommands.pushmainwindow2top"/> </hc:eventtrigger> </hc:interaction.triggers> </hc:notifyicon>
上面的代码,一个托盘菜单基本上算完事了,简单说一下:
【step 4】手动关闭主窗体时,隐藏而不退出
添加了托盘菜单后,在关闭主窗体时,应该重写onclosing事件,隐藏主窗体,而不是直接关闭它。
protected override void onclosing(canceleventargs e) { this.hide(); e.cancel = true; }
更多demo源码请参考 handycontrol
本文源码terminalmacs
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
asp.net搭建博客,使用BlogEngine.NET+MySql搭建博客
网友评论