更改图标单击时通知 [英] Change Icon Notify on Click
本文介绍了更改图标单击时通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
单击时是否可能有更改者notifyicon1?该程序是用c#
is possible changer notifyicon1 on click? the program is writed in c#
推荐答案
是的. 只需通过 NotifyIcon.Icon属性 [ ^ ]
Yes it is.
Just assign a new Icon via NotifyIcon.Icon Property[^]
在第一个答案之后,此示例 [ ^ ](尽管在VB.Net中)应该可以帮到你.
使用NotifyIcon应用程序托盘图标显示进度 [
Further to the first answer, this sample[^] (though in VB.Net) should help you out.
Show progress using the NotifyIcon application tray icon[^] should help you out as well.
使用系统;
使用System.Drawing;
使用System.Windows.Forms;
公共类Form1:System.Windows.Forms.Form
{
私有System.Windows.Forms.NotifyIcon notifyIcon1;
私有System.Windows.Forms.ContextMenu contextMenu1;
私有System.Windows.Forms.MenuItem menuItem1;
私有System.ComponentModel.IContainer组件;
[STAThread]
静态void Main()
{
Application.Run(new Form1());
}
公共Form1()
{
this.components = new System.ComponentModel.Container();
this.contextMenu1 =新的System.Windows.Forms.ContextMenu();
this.menuItem1 =新的System.Windows.Forms.MenuItem();
//初始化contextMenu1
this.contextMenu1.MenuItems.AddRange(
新的System.Windows.Forms.MenuItem [] {this.menuItem1});
//初始化menuItem1
this.menuItem1.Index = 0;
this.menuItem1.Text ="E&xit";
this.menuItem1.Click + =新的System.EventHandler(this.menuItem1_Click);
//设置表单的显示方式.
this.ClientSize = new System.Drawing.Size(292,266);
this.Text =通知图标示例";
//创建NotifyIcon.
this.notifyIcon1 =新的System.Windows.Forms.NotifyIcon(this.components);
//Icon属性设置将出现的图标
//在此应用程序的系统托盘中.
notifyIcon1.Icon = new Icon("appicon.ico");
//ContextMenu属性设置菜单,该菜单将
//右键单击系统托盘图标时出现.
notifyIcon1.ContextMenu = this.contextMenu1;
//Text属性设置将要显示的文本,
//在工具提示中,当鼠标悬停在系统托盘图标上时.
notifyIcon1.Text ="Form1(NotifyIcon示例)";
notifyIcon1.Visible = true;
//处理DoubleClick事件以激活表单.
notifyIcon1.DoubleClick + =新的System.EventHandler(this.notifyIcon1_DoubleClick);
}
受保护的覆盖无效void Dispose(布尔处理)
{
//清理所有正在使用的组件.
if(处理)
if(components!= null)
components.Dispose();
base.Dispose(处理);
}
私人void notifyIcon1_DoubleClick(object Sender,EventArgs e)
{
//当用户双击通知图标时显示表单.
//如果最小化窗体,则将WindowState设置为normal.
如果(this.WindowState == FormWindowState.Minimized)
this.WindowState = FormWindowState.Normal;
//激活表格.
this.Activate();
}
private void menuItem1_Click(object Sender,EventArgs e){
//关闭表单,这将关闭应用程序.
this.Close();
}
}
using System;
using System.Drawing;
using System.Windows.Forms;
public class 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 components;
[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();
// Initialize contextMenu1
this.contextMenu1.MenuItems.AddRange(
new System.Windows.Forms.MenuItem[] {this.menuItem1});
// Initialize menuItem1
this.menuItem1.Index = 0;
this.menuItem1.Text = "E&xit";
this.menuItem1.Click += new System.EventHandler(this.menuItem1_Click);
// Set up how the form should be displayed.
this.ClientSize = new System.Drawing.Size(292, 266);
this.Text = "Notify Icon Example";
// Create the NotifyIcon.
this.notifyIcon1 = new System.Windows.Forms.NotifyIcon(this.components);
// The Icon property sets the icon that will appear
// in the systray for this application.
notifyIcon1.Icon = new Icon("appicon.ico");
// The ContextMenu property sets the menu that will
// appear when the systray icon is right clicked.
notifyIcon1.ContextMenu = this.contextMenu1;
// The Text property sets the text that will be displayed,
// in a tooltip, when the mouse hovers over the systray icon.
notifyIcon1.Text = "Form1 (NotifyIcon example)";
notifyIcon1.Visible = true;
// Handle the DoubleClick event to activate the form.
notifyIcon1.DoubleClick += new System.EventHandler(this.notifyIcon1_DoubleClick);
}
protected override void Dispose( bool disposing )
{
// Clean up any components being used.
if( disposing )
if (components != null)
components.Dispose();
base.Dispose( disposing );
}
private void notifyIcon1_DoubleClick(object Sender, EventArgs e)
{
// Show the form when the user double clicks on the notify icon.
// Set the WindowState to normal if the form is minimized.
if (this.WindowState == FormWindowState.Minimized)
this.WindowState = FormWindowState.Normal;
// Activate the form.
this.Activate();
}
private void menuItem1_Click(object Sender, EventArgs e) {
// Close the form, which closes the application.
this.Close();
}
}
这篇关于更改图标单击时通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文