一个菜单栏
一个按钮
public partial class FrmMain : Form
{
bool isExit = false;
public FrmMain()
{
InitializeComponent();
}
private void FrmMain_Load(object sender, EventArgs e)
{
this.WindowState = FormWindowState.Maximized;
this.notifyIcon1.Visible = false;
}
private void FrmMain_FormClosing(object sender, FormClosingEventArgs e)
{
if (!isExit)
{
e.Cancel = true;
this.Hide();
this.tool_exit.PerformClick(); //默认是最小化
}
}
private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)
{
this.Show();
this.WindowState = FormWindowState.Maximized;
}
private void ContextM_open_Click(object sender, EventArgs e)
{
this.Show();
this.WindowState = FormWindowState.Maximized;
}
private void contextM_exit_Click(object sender, EventArgs e)
{
// ***************************************************************************************
string message = "你确定退出本程序?";
string caption = "提示信息!";
MessageBoxIcon msgBoxIcon = MessageBoxIcon.Information;
MessageBoxButtons msgBtn = MessageBoxButtons.OKCancel;
DialogResult result = MessageBox.Show(message, caption, msgBtn, msgBoxIcon);
if (result == System.Windows.Forms.DialogResult.OK)
{
isExit = true;
Application.Exit();
}
}
private void tool_exit_Click(object sender, EventArgs e)//仅托盘图标,默认退出要点击右键
{
if (!isExit)
{
// ***************************************************************************************
this.Hide();
//notifyIcon1.Icon = this.Icon;
notifyIcon1.Text = "计划任务执行";
this.notifyIcon1.Visible = true;
this.notifyIcon1.ShowBalloonTip(5000, "提示", "系统仍在运行!", ToolTipIcon.Info);
// ***************************************************************************************
}
}
}