using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
int i = 1;
int exit = 1;//1代表退出,0代表最小化
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
if (i==1)
{
DialogResult dr= MessageBox.Show("最小化到托盘?","退出程序?",MessageBoxButtons.YesNo,MessageBoxIcon.Question);
if (dr==DialogResult.Yes)
{
exit = 0;
}
else
{
exit = 1;
}
}
i++;
if (exit==0)
{
e.Cancel = true;
this.WindowState = FormWindowState.Minimized;
//this.Close();
}
else
{
}
}
private void button1_Click(object sender, EventArgs e)
{
i = 3;
exit = 1;
this.Close();
}
private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)
{
this.Show();
this.Activate();
this.WindowState = FormWindowState.Normal;
}
private void Form1_Resize(object sender, EventArgs e)
{
if (this.WindowState==FormWindowState.Minimized)
{
this.Hide();
//this.notifyIcon1.BalloonTipTitle = "肥牛温馨提示!";
//this.notifyIcon1.BalloonTipText = "这里隐藏了你的肥牛,双击打开";
//this.notifyIcon1.ShowBalloonTip(5000);
this.notifyIcon1.ShowBalloonTip(5000, "肥牛温馨提示!", "在这里", ToolTipIcon.Info);
}
}
private void timer1_Tick(object sender, EventArgs e)
{
if (progressBar1.Value==progressBar1.Maximum)
{
//timer1.Stop();
progressBar1.Value = 0;
}
progressBar1.Value++;
int p = progressBar1.Value * 100 / progressBar1.Maximum;
button1.Text = p + "%";
}
private void button2_Click(object sender, EventArgs e)
{
timer1.Enabled = true;
}
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
int i = 1;
int exit = 1;//1代表退出,0代表最小化
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
if (i==1)
{
DialogResult dr= MessageBox.Show("最小化到托盘?","退出程序?",MessageBoxButtons.YesNo,MessageBoxIcon.Question);
if (dr==DialogResult.Yes)
{
exit = 0;
}
else
{
exit = 1;
}
}
i++;
if (exit==0)
{
e.Cancel = true;
this.WindowState = FormWindowState.Minimized;
//this.Close();
}
else
{
}
}
private void button1_Click(object sender, EventArgs e)
{
i = 3;
exit = 1;
this.Close();
}
private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)
{
this.Show();
this.Activate();
this.WindowState = FormWindowState.Normal;
}
private void Form1_Resize(object sender, EventArgs e)
{
if (this.WindowState==FormWindowState.Minimized)
{
this.Hide();
//this.notifyIcon1.BalloonTipTitle = "肥牛温馨提示!";
//this.notifyIcon1.BalloonTipText = "这里隐藏了你的肥牛,双击打开";
//this.notifyIcon1.ShowBalloonTip(5000);
this.notifyIcon1.ShowBalloonTip(5000, "肥牛温馨提示!", "在这里", ToolTipIcon.Info);
}
}
private void timer1_Tick(object sender, EventArgs e)
{
if (progressBar1.Value==progressBar1.Maximum)
{
//timer1.Stop();
progressBar1.Value = 0;
}
progressBar1.Value++;
int p = progressBar1.Value * 100 / progressBar1.Maximum;
button1.Text = p + "%";
}
private void button2_Click(object sender, EventArgs e)
{
timer1.Enabled = true;
}
}
}
设计界面: