using
System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using bank;
namespace WindowsApplication1
... {
public partial class Form1 : Form
...{
public Form1()
...{
InitializeComponent();
Initializenotifyicon();
}
// private Icon mNetTrayIcon = new Icon("app.ico");//托盘图标
// private NotifyIcon TrayIcon;//创建托盘组件
private ContextMenu notifyiconMnu;//创建托盘菜单
private void Initializenotifyicon() //托盘菜单程序
...{
MenuItem[] mnuItms = new MenuItem[6];//设置菜单项数
mnuItms[0] = new MenuItem();//菜单项1
mnuItms[0].Text = "说 明";//标题
// mnuItms[0].Click += new System.EventHandler(this.ExitSelect);//菜单触发的事件
//这里的ExitSelect是点击菜单后运行的事件名
mnuItms[1] = new MenuItem("-");//菜单项2,在菜单中产生行装饰条
mnuItms[2] = new MenuItem();//菜单项3,显示窗口
mnuItms[2].Text = "恢复窗口";
// mnuItms[2].Click += new System.EventHandler(this.chuangkou);
mnuItms[3] = new MenuItem();//菜单项4,隐藏窗口
mnuItms[3].Text = "最小化运行";
// mnuItms[3].Click += new System.EventHandler(this.yincang);
mnuItms[4] = new MenuItem("-");//菜单项5
mnuItms[5] = new MenuItem();//菜单项6,退出程序
mnuItms[5].Text = "退出系统";
mnuItms[5].Click += new System.EventHandler(this.clicka);
notifyiconMnu = new ContextMenu(mnuItms);
notifyIcon1.ContextMenu = notifyiconMnu;
}
//public void yincang(object sender, System.EventArgs e)//隐藏窗体菜单事件
//{
// //this.WindowState = System.Windows.Forms.FormWindowState.Minimized;//窗体最小化
// //this.ShowInTaskbar = false;//在任务栏中隐藏窗体
//}
// public void chuangkou(object sender, System.EventArgs e)//显示窗体菜单事件
// {
// MessageBox.Show(this.WindowState.ToString());
// //if (this.WindowState == FormWindowState.Minimized)
// //{
// // this.Visible = false;
// // this.notifyIcon1.Visible = true;
// //}
// //this.WindowState = FormWindowState.Normal;//按实际设置值显示窗体
// //this.ShowInTaskbar = true;//在任务栏中隐藏窗体
/**///// this.ShowInTaskbar = false;//打开窗体
// this.Visible = true;
// this.notifyIcon1.Visible = true;
// }
public void clicka(object sender, System.EventArgs e)//退出系统菜单事件
...{
notifyIcon1.Dispose();//释放托盘资源
Application.Exit();//释放所有资源
this.Dispose();//清理所有资源
}
// public void ExitSelect(object sender, System.EventArgs e)//帮助菜单事件
//{
// MessageBox.Show("这是一个托盘菜单演示程序!");
//}
private void notifyIcon1_DoubleClick(object sender, EventArgs e)
...{
if (this.Visible == true) //根据窗口的显示和隐藏设置Trayico对象的显示
...{
this.Hide();
this.notifyIcon1.Visible = true;
}
else
...{
this.Show();
this.notifyIcon1.Visible = false;
}
}
private void Addcustomer_Click(object sender, EventArgs e)
...{
BankCustomer c;
c = new BankCustomer();
c.FirstName = this.FistName.Text;
c.LastName = this.LastName.Text;
c.Balance = Decimal.Parse(this.banlence.Text);
this.ListCustomer.Items.Add(c);
}
private void button1_Click(object sender, EventArgs e)
...{
BankCustomer c;
c = new BankCustomer();
c.FirstName = this.FistName.Text;
c.LastName = this.LastName.Text+"hhhh";
c.Balance = Decimal.Parse(this.banlence.Text);
this.ListCustomer.Items.Add(c);
}
private void button2_Click(object sender, EventArgs e)
...{
this.Addcustomer.Click -= new System.EventHandler(this.Addcustomer_Click);
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
...{
e.Cancel = true;
this.Hide();
this.notifyIcon1.Visible = true;
}
private void button3_Click(object sender, EventArgs e)
...{
this.webBrowser1.Navigate(this.textBox1.Text);
}
}
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using bank;
namespace WindowsApplication1
... {
public partial class Form1 : Form
...{
public Form1()
...{
InitializeComponent();
Initializenotifyicon();
}
// private Icon mNetTrayIcon = new Icon("app.ico");//托盘图标
// private NotifyIcon TrayIcon;//创建托盘组件
private ContextMenu notifyiconMnu;//创建托盘菜单
private void Initializenotifyicon() //托盘菜单程序
...{
MenuItem[] mnuItms = new MenuItem[6];//设置菜单项数
mnuItms[0] = new MenuItem();//菜单项1
mnuItms[0].Text = "说 明";//标题
// mnuItms[0].Click += new System.EventHandler(this.ExitSelect);//菜单触发的事件
//这里的ExitSelect是点击菜单后运行的事件名
mnuItms[1] = new MenuItem("-");//菜单项2,在菜单中产生行装饰条
mnuItms[2] = new MenuItem();//菜单项3,显示窗口
mnuItms[2].Text = "恢复窗口";
// mnuItms[2].Click += new System.EventHandler(this.chuangkou);
mnuItms[3] = new MenuItem();//菜单项4,隐藏窗口
mnuItms[3].Text = "最小化运行";
// mnuItms[3].Click += new System.EventHandler(this.yincang);
mnuItms[4] = new MenuItem("-");//菜单项5
mnuItms[5] = new MenuItem();//菜单项6,退出程序
mnuItms[5].Text = "退出系统";
mnuItms[5].Click += new System.EventHandler(this.clicka);
notifyiconMnu = new ContextMenu(mnuItms);
notifyIcon1.ContextMenu = notifyiconMnu;
}
//public void yincang(object sender, System.EventArgs e)//隐藏窗体菜单事件
//{
// //this.WindowState = System.Windows.Forms.FormWindowState.Minimized;//窗体最小化
// //this.ShowInTaskbar = false;//在任务栏中隐藏窗体
//}
// public void chuangkou(object sender, System.EventArgs e)//显示窗体菜单事件
// {
// MessageBox.Show(this.WindowState.ToString());
// //if (this.WindowState == FormWindowState.Minimized)
// //{
// // this.Visible = false;
// // this.notifyIcon1.Visible = true;
// //}
// //this.WindowState = FormWindowState.Normal;//按实际设置值显示窗体
// //this.ShowInTaskbar = true;//在任务栏中隐藏窗体
/**///// this.ShowInTaskbar = false;//打开窗体
// this.Visible = true;
// this.notifyIcon1.Visible = true;
// }
public void clicka(object sender, System.EventArgs e)//退出系统菜单事件
...{
notifyIcon1.Dispose();//释放托盘资源
Application.Exit();//释放所有资源
this.Dispose();//清理所有资源
}
// public void ExitSelect(object sender, System.EventArgs e)//帮助菜单事件
//{
// MessageBox.Show("这是一个托盘菜单演示程序!");
//}
private void notifyIcon1_DoubleClick(object sender, EventArgs e)
...{
if (this.Visible == true) //根据窗口的显示和隐藏设置Trayico对象的显示
...{
this.Hide();
this.notifyIcon1.Visible = true;
}
else
...{
this.Show();
this.notifyIcon1.Visible = false;
}
}
private void Addcustomer_Click(object sender, EventArgs e)
...{
BankCustomer c;
c = new BankCustomer();
c.FirstName = this.FistName.Text;
c.LastName = this.LastName.Text;
c.Balance = Decimal.Parse(this.banlence.Text);
this.ListCustomer.Items.Add(c);
}
private void button1_Click(object sender, EventArgs e)
...{
BankCustomer c;
c = new BankCustomer();
c.FirstName = this.FistName.Text;
c.LastName = this.LastName.Text+"hhhh";
c.Balance = Decimal.Parse(this.banlence.Text);
this.ListCustomer.Items.Add(c);
}
private void button2_Click(object sender, EventArgs e)
...{
this.Addcustomer.Click -= new System.EventHandler(this.Addcustomer_Click);
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
...{
e.Cancel = true;
this.Hide();
this.notifyIcon1.Visible = true;
}
private void button3_Click(object sender, EventArgs e)
...{
this.webBrowser1.Navigate(this.textBox1.Text);
}
}
}