📄 form1.cs
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace Suoxiao
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
int flag = 0;//退出系统还是最小化到托盘标志位
private void Form1_SizeChanged(object sender, EventArgs e)
{
if (this.WindowState == FormWindowState.Minimized)
{
this.HideServer();
}
}
private void notifyIcon1_Click(object sender, EventArgs e)
{
this.Visible = true;
this.WindowState = FormWindowState.Normal;
this.notifyIcon1.Visible = true;
}
private void notifyIcon1_DoubleClick(object sender, EventArgs e)
{
this.ShowServer();
}
private void menuItem_Hide_Click(object sender, EventArgs e)
{
this.HideServer();
}
private void menuItem_Show_Click(object sender, EventArgs e)
{
this.ShowServer();
}
private void menuItem_Exit_Click(object sender, EventArgs e)
{
this.Dispose();
}
protected override void OnClosing(CancelEventArgs e)
{
//ExitOrNot remind = new ExitOrNot(flag);
//System.Windows.Forms.DialogResult result = remind.ShowDialog();
//if (result == System.Windows.Forms.DialogResult.OK)
//{
// flag = remind.flag;
// if (flag == 1)//退出
// {
// e.Cancel = false;
// this.Dispose();
// Application.Exit();
// }
// if (flag == 2)
// {
// e.Cancel = true;
// this.WindowState = FormWindowState.Minimized;
// this.HideServer();//
// }
//}
//else
//{
//// if (result == System.Windows.Forms.DialogResult.Cancel)
//// {
//// flag1 = true;//退出系统
//// }
// e.Cancel = true;
//}
// base.OnClosing(e);
}
public void HideServer()
{
this.Hide();
this.notifyIcon1.Visible = true;
}
private void ShowServer()
{
this.Show();
this.WindowState = FormWindowState.Normal;
this.Activate();
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
ExitOrNot remind = new ExitOrNot(flag);
System.Windows.Forms.DialogResult result = remind.ShowDialog();
if (result == System.Windows.Forms.DialogResult.OK)
{
flag = remind.flag;
if (flag == 1)//退出
{
e.Cancel = false;
this.Dispose();
Application.Exit();
}
if (flag == 2)
{
e.Cancel = true;
this.WindowState = FormWindowState.Minimized;
this.HideServer();//
}
}
else
{
e.Cancel = true;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -