パレットアイコン
2752 ワード
public partial class Form4 : Form
{
private NotifyIcon notifyIcon = null;//
private ContextMenu contextMenu = null;
private MenuItem menuItem1;
private MenuItem menuItem2;
public Form4()
{
InitializeComponent();
if (notifyIcon == null)
{
notifyIcon = new NotifyIcon();
}
notifyIcon.Icon = new Icon("es.ico");
menuItem1 = new MenuItem(" ");
menuItem2 = new MenuItem(" ");
menuItem1.Click += new EventHandler(menuItem1_Click);
menuItem2.Click += new EventHandler(menuItem2_Click);
contextMenu = new ContextMenu();
contextMenu.MenuItems.Add(menuItem1);
contextMenu.MenuItems.Add(menuItem2);
notifyIcon.ContextMenu = contextMenu;
notifyIcon.Text = " ";
notifyIcon.DoubleClick += new EventHandler(notifyIcon_DoubleClick);
}
private void menuItem1_Click(object sender, EventArgs e)
{
if (this.WindowState == FormWindowState.Minimized)
{
this.Show();
this.WindowState = FormWindowState.Normal; //
}
}
private void menuItem2_Click(object sender, EventArgs e)
{
Application.Exit();
notifyIcon.Dispose();
}
private void notifyIcon_DoubleClick(object sender, EventArgs e)
{
if (this.WindowState == FormWindowState.Minimized)
{
this.Show();
this.WindowState = FormWindowState.Normal; //
}
}
private void Form4_Load(object sender, EventArgs e)
{
}
private void Form4_SizeChanged(object sender, EventArgs e)
{
if (this.WindowState == FormWindowState.Normal)
{
notifyIcon.Visible = false; //
}
if (this.WindowState == FormWindowState.Minimized)//
{
this.Hide();//
notifyIcon.Visible = true;
}
}
private void Form4_FormClosing(object sender, FormClosingEventArgs e)
{
Application.Exit();
notifyIcon.Dispose();
}
}