1.托盘的程序代码如下:
using System ;
using System.Drawing ;
using System.Collections ;
using System.ComponentModel ;
using System.Windows.Forms ;
using System.Data ;//导入在程序中使用到的名称空间
namespace WindowsApplication1
{
public class Tray : Form
{
private System.ComponentModel.Container components = null ;
private Icon mNetTrayIcon = new Icon ( "NET10B.ico" ) ;
private NotifyIcon TrayIcon ;
private ContextMenu notifyiconMnu ; public Tray()
{
//初始化窗体中使用到的组件
InitializeComponent ( ) ;
//初始化托盘程序的各个要素
Initializenotifyicon ( ) ;
} private void Initializenotifyicon ( )
{
//设定托盘程序的各个属性
TrayIcon = new NotifyIcon ( ) ;
TrayIcon.Icon = mNetTrayIcon ;
TrayIcon.Text = "辽河应用服务器" ;
TrayIcon.Visible = true ;
TrayIcon.DoubleClick += new System.EventHandler ( this.Tray_DoubleClick ) ; //定义一个MenuItem数组,并把此数组同时赋值给ContextMenu对象
MenuItem [ ] mnuItms = new MenuItem [ 3 ] ;
mnuItms [ 0 ] = new MenuItem ( ) ;
mnuItms [ 0 ] .Text = "辽河应用服务器!" ;
mnuItms [ 0 ] .Click += new System.EventHandler ( this.showmessage ) ; mnuItms [ 1 ] = new MenuItem ( "-" ) ; mnuItms [ 2 ] = new MenuItem ( ) ;
mnuItms [ 2 ] .Text = "退出系统" ;
mnuItms [ 2 ] .Click += new System.EventHandler ( this.ExitSelect ) ;
mnuItms [ 2 ] .DefaultItem = true ; notifyiconMnu = new ContextMenu ( mnuItms ) ;
TrayIcon.ContextMenu = notifyiconMnu ;
//为托盘程序加入设定好的ContextMenu对象
}// public void click ( object sender , System.EventArgs e )
// {
// MessageBox.Show ( "Visual C#编写托盘程序中的事件响应" ) ;
// } public void showmessage ( object sender , System.EventArgs e )
{
MessageBox.Show ( "事件代码还未编写!" ) ;
} public void ExitSelect ( object sender , System.EventArgs e )
{
//隐藏托盘程序中的图标
TrayIcon.Visible = false ;
//关闭系统
this.Close ( ) ;
} //清除程序中使用过的资源
// protected override void Dispose ( )
// {
// base.Dispose ( ) ;
// if ( components != null )
// components.Dispose ( ) ;
// } protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
} private void InitializeComponent ( )
{
//
// Tray
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(409, 64);
//this.ControlBox = false;
this.MaximizeBox = false;
//this.MinimizeBox = false;
this.Name = "Tray";
this.ShowInTaskbar = false;
this.Text = "用Visual C#做托盘程序!";
this.DoubleClick += new System.EventHandler(this.Tray_DoubleClick); } static void Main ( )
{
Application.Run ( new Tray ( ) ) ;
} private void Tray_DoubleClick(object sender, System.EventArgs e)
{
MessageBox.Show ( "Visual C#编写托盘程序中的事件响应" ) ;
}
}
}2.用DOM肯定会慢,用SAX可能快一点.
using System ;
using System.Drawing ;
using System.Collections ;
using System.ComponentModel ;
using System.Windows.Forms ;
using System.Data ;//导入在程序中使用到的名称空间
namespace WindowsApplication1
{
public class Tray : Form
{
private System.ComponentModel.Container components = null ;
private Icon mNetTrayIcon = new Icon ( "NET10B.ico" ) ;
private NotifyIcon TrayIcon ;
private ContextMenu notifyiconMnu ; public Tray()
{
//初始化窗体中使用到的组件
InitializeComponent ( ) ;
//初始化托盘程序的各个要素
Initializenotifyicon ( ) ;
} private void Initializenotifyicon ( )
{
//设定托盘程序的各个属性
TrayIcon = new NotifyIcon ( ) ;
TrayIcon.Icon = mNetTrayIcon ;
TrayIcon.Text = "辽河应用服务器" ;
TrayIcon.Visible = true ;
TrayIcon.DoubleClick += new System.EventHandler ( this.Tray_DoubleClick ) ; //定义一个MenuItem数组,并把此数组同时赋值给ContextMenu对象
MenuItem [ ] mnuItms = new MenuItem [ 3 ] ;
mnuItms [ 0 ] = new MenuItem ( ) ;
mnuItms [ 0 ] .Text = "辽河应用服务器!" ;
mnuItms [ 0 ] .Click += new System.EventHandler ( this.showmessage ) ; mnuItms [ 1 ] = new MenuItem ( "-" ) ; mnuItms [ 2 ] = new MenuItem ( ) ;
mnuItms [ 2 ] .Text = "退出系统" ;
mnuItms [ 2 ] .Click += new System.EventHandler ( this.ExitSelect ) ;
mnuItms [ 2 ] .DefaultItem = true ; notifyiconMnu = new ContextMenu ( mnuItms ) ;
TrayIcon.ContextMenu = notifyiconMnu ;
//为托盘程序加入设定好的ContextMenu对象
}// public void click ( object sender , System.EventArgs e )
// {
// MessageBox.Show ( "Visual C#编写托盘程序中的事件响应" ) ;
// } public void showmessage ( object sender , System.EventArgs e )
{
MessageBox.Show ( "事件代码还未编写!" ) ;
} public void ExitSelect ( object sender , System.EventArgs e )
{
//隐藏托盘程序中的图标
TrayIcon.Visible = false ;
//关闭系统
this.Close ( ) ;
} //清除程序中使用过的资源
// protected override void Dispose ( )
// {
// base.Dispose ( ) ;
// if ( components != null )
// components.Dispose ( ) ;
// } protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
} private void InitializeComponent ( )
{
//
// Tray
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(409, 64);
//this.ControlBox = false;
this.MaximizeBox = false;
//this.MinimizeBox = false;
this.Name = "Tray";
this.ShowInTaskbar = false;
this.Text = "用Visual C#做托盘程序!";
this.DoubleClick += new System.EventHandler(this.Tray_DoubleClick); } static void Main ( )
{
Application.Run ( new Tray ( ) ) ;
} private void Tray_DoubleClick(object sender, System.EventArgs e)
{
MessageBox.Show ( "Visual C#编写托盘程序中的事件响应" ) ;
}
}
}2.用DOM肯定会慢,用SAX可能快一点.
解决方案 »
- C# 怎么调用C++写的DLL函数里带着省略号参数
- 请问C# 类里面的 get 和 set 到底是个什么情况 ???? 字段 类 属性 方法 ????
- 关于获取在窗体上单击鼠标时的位置,在线等
- c# 如何实现文件储存?
- 多线程编程的效率问题
- 如何让两个程序不能同时运行?
- 当鼠标经过datagrid如何显示这一格绑定的内容?
- C#(WinForm)中For循环自动打开某个网页怎么做呢?
- C#初学者:在c#中如何把一个文件以二进制代码存入到数据库中?
- C#求助,调用Excel函数Irr出错
- 为什么我用label能正确显示邮件的HtmlBody,但用TextBox却不行啊
- ReadFile() API函数导入的原型应该怎么写? 我的在下面,但不行,:(
Programming in C#.
http://tech.sina.com.cn/c/2002-01-16/8472.html
RegistryKey RegKey;
RegKey=Registry.ClassesRoot;
RegKey=RegKey.CreateSubKey("*\\shell\\MyApp");
RegKey.SetValue("","lovered");
RegKey=Registry.ClassesRoot;
RegKey=RegKey.CreateSubKey("*\\shell\\MyApp\\command");
RegKey.SetValue("",p.MainWindowTitle+" %1");
RegKey.Close();