1
zrg
2 天以前 c4c02944532a9bfda6de9a0cd85a9dfa631ed003
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using WebAPI.Controllers;
namespace LMES
{
    public partial class XiaoZhuGe_autoGetData : Form
    {
        public XiaoZhuGe_autoGetData()
        {
            InitializeComponent();
 
            //为系统托盘图标增加 右击菜单项
            ContextMenu contextMenu = new ContextMenu();
            MenuItem exitMenuItem = new MenuItem("退出");
            exitMenuItem.Click += ExitMenuItem_Click;
            contextMenu.MenuItems.Add(exitMenuItem);
            notifyIcon_Icon.ContextMenu = contextMenu;
 
            //页面初始化
            set_initPage();
        }
 
        #region 页面初始化
        public void set_initPage()
        {
            timer1.Enabled = true;
        }
        #endregion
 
        #region 定时器1:用于隐藏页面与任务栏图标
        private void timer1_Tick(object sender, EventArgs e)
        {
            //系统托盘显示软件图标
            this.notifyIcon_Icon.Visible = true;
            // 隐藏主窗体
            this.Hide();
            // 隐藏任务栏软件图标
            this.ShowInTaskbar = false;
 
            timer1.Enabled = false;
        }
        #endregion
 
        #region 定时器2:用于定时同步数据
        private void timer2_Tick(object sender, EventArgs e)
        {
            try
            {
                XZG_DataSynchronizationController t = new XZG_DataSynchronizationController();
                t.dataAnsy();
            }catch(Exception e1)
            {
                string sErrMsg = "";
            }
        }
        #endregion
 
        #region 系统托盘点击图标后图标仍存在
        private void notifyIcon_Icon_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            
 
            if (e.Button == MouseButtons.Left && e.Clicks == 2) // 双击左键事件示例
            {
                // 处理双击事件,例如显示或隐藏主窗体等。
                //this.Show(); // 示例:显示主窗体(如果之前是隐藏的)
                //this.WindowState = FormWindowState.Normal; // 确保窗口处于正常状态(非最小化)
 
                //系统托盘显示软件图标
                this.notifyIcon_Icon.Visible = true;        //保证系统托盘图标仍旧存在
            }
        }
        #endregion
 
        #region 系统托盘图标 右击功能菜单退出按钮事件
        private void ExitMenuItem_Click(object sender, EventArgs e)
        {
            Application.Exit(); // 这将关闭整个应用程序
        }
        #endregion
    }
}