单击更改图标通知(Change Icon Notify on Click)
IT问题网 2021-01-18 00:00:00
问 题
是否可以点击更换器notifyicon1?该程序在c#中写入
解决方案
是的。
只需通过notifyicon.icon property[ ^ ]
继续第一个回答,此示例 [ ^ ](虽然在vb.net中)应该可以帮到你。
使用notifyicon应用程序托盘图标显示进度 [ ^ ]也应该帮助你。
使用system;
使用system.drawing;
使用system.windows.forms;
公共类form1:system.windows.forms.form
{
private system.windows.forms.notifyicon notifyicon1;
private system。 windows.forms.contextmenu contextmenu1;
private system.windows.forms.menuitem menuitem1;
private system.componentmodel.icontainer组件;
[stathread]
static void main()
{
application.run(new form1());
}
public form1()
{
this.components = new system.componentmodel.container();
this.contextmenu1 = new system.windows.forms.contextmenu();
this.menuitem1 = new system.windows.forms .menuitem();
//初始化contextmenu1
this.contextmenu1.menuitems .addrange(
new system.windows.forms.menuitem [] {this.menuitem1});
//初始化menuitem1
this.menuitem1.index = 0;
this.menuitem1.text ="exit";
this.menuitem1.click + = new system。 eventhandler(this.menuitem1_click);
//设置表单的显示方式。
this.clientsize = new system.drawing .size(292,266);
this.text ="通知图标示例";
//创建notifyicon。
this.notifyicon1 = new system.windows.forms.notifyicon(this.components);
// icon属性设置图标在这个应用程序的系统托盘中出现
//
notifyicon1.icon = new icon("appicon.ico");
// contextmenu属性设置菜单
// app右键单击系统托盘图标时听到。
notifyicon1.contextmenu = this.contextmenu1;
// text属性设置文本当鼠标悬停在系统托盘图标上时,将显示工具提示中的
//
notifyicon1.text ="form1(notifyicon示例)";
notifyicon1.visible = true;
//处理doubleclick事件以激活表单。
notifyicon1.doubleclick + = new system.eventhandler(this.notifyicon1_doubleclick);
}
protected override void dispose(bool处理)
{
//清理正在使用的任何组件。
if(处理)
if(b) components!= null)
components.dispose();
base.dispose(disposing);
}
private void notifyicon1_doubleclick(object sender,eventargs e)
{
//当用户双击通知图标时显示表单。
//如果窗体最小化,则将windowstate设置为正常。
if(this.windowstate == formwindowstate.minimized)
this.windowstate = formwindowstate.normal;
//激活表格。
this.activate();
}
private void menuitem1_click(object sender,eventargs e){
//关闭表单,关闭应用程序。
this.close();
}
}
分享:
热门推荐