您的位置:首页 > 编程语言 > C#

How to Create a Notify Icon in C# without a form

2006-09-16 14:11 489 查看
参考: http://bluehouse.wordpress.com/2006/01/24/how-to-create-a-notify-icon-in-c-without-a-form/

Tested with .NET Framework 2.0 and Windows XP Professional SP2.

我想创建一个带Notify Icon的应用程序,但是不需要Forms。那么如何编写一个没有窗体的NotifyIcon程序哪?我找到了 http://bluehouse.wordpress.com/2006/01/24/how-to-create-a-notify-icon-in-c-without-a-form/ 。稍做修改,形成如下代码:

1 using System;
2 using System.Collections.Generic;
3 using System.Text;
4 using System.Windows.Forms;
5 using System.ComponentModel;
6 using System.Drawing;
7
8 class Portal
9 {
private IContainer container;
private NotifyIcon notifyIcon;

public Portal()
{
Icon icon = new Icon(SystemIcons.Application, 16, 16);

this.container = new Container();
this.notifyIcon = new NotifyIcon(this.container);
this.notifyIcon.Icon = icon;
this.notifyIcon.Visible = true;
}
}

static class Program
{
[STAThread]
static void Main()
{
new Portal();
Application.Run();
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: