public MainWindow() { InitializeComponent(); AppSet.AppMainWindow = this; //以下代码,修复窗体全屏时覆盖任务栏以及大小不正确问题。 FullScreenManager.RepairWpfWindowFullScreenBehavior(this); //设定升级检测定时器 _UpdateAppTimer = new System.Windows.Threading.DispatcherTimer(); _UpdateAppTimer.Tick += new EventHandler(async(x, y) => { await CheckAppUpdateAsync(); }); _UpdateAppTimer.Interval = new TimeSpan(0, 0, 0); //设定网络状态检测定时器 _CheckNetStateTimer = new System.Windows.Threading.DispatcherTimer(); _CheckNetStateTimer.Tick += new EventHandler(async(x, y) => { await CheckNetStateAsync(); }); _CheckNetStateTimer.Interval = new TimeSpan(0, 0, 10); #region 显示系统托盘图标 //系统托盘显示 this.notifyIcon = new NotifyIcon(); this.notifyIcon.BalloonTipText = "系统监控中... ..."; this.notifyIcon.ShowBalloonTip(2000); this.notifyIcon.Text = "政工业务工作平台"; //this.notifyIcon.Icon = new System.Drawing.Icon(@"AppIcon.ico"); this.notifyIcon.Icon = System.Drawing.Icon.ExtractAssociatedIcon(System.Windows.Forms.Application.ExecutablePath); this.notifyIcon.Visible = true; //托盘右键菜单项 this.notifyIcon.ContextMenuStrip = new ContextMenuStrip(); this.notifyIcon.ContextMenuStrip.Height = 300; this.notifyIcon.ContextMenuStrip.Items.Add("显示主窗口", null, (sender, eventArgs) => { if (WinLockDialog.ThisWinObj != null) { //说明该锁定窗口已经打开 WinLockDialog.ThisWinObj.Activate(); return; } if (AppSet.AppIsLocked) { WinLockDialog wld = new WinLockDialog(); if (!wld.ShowDialog().Value) { return; } } AppSet.AppIsLocked = false; this.Visibility = System.Windows.Visibility.Visible; this.ShowActivated = true; this.ShowInTaskbar = true; this.WindowState = WindowState.Maximized; this.Activate(); }); this.notifyIcon.ContextMenuStrip.Items.Add("关闭显示器", null, (sender, eventArgs) => { CloseScreen.Close(); }); this.notifyIcon.ContextMenuStrip.Items.Add("锁定软件", null, (sender, eventArgs) => { LockApp(); }); this.notifyIcon.ContextMenuStrip.Items.Add("关闭程序", null, (sender, eventArgs) => { ShutDownApp(); }); //托盘双击响应 this.notifyIcon.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler((o, e) => { if (e.Button == MouseButtons.Left) { this.notifyIcon.ContextMenuStrip.Items[0].PerformClick(); } }); #endregion }
private void BtnCloseScreen_Click(object sender, RoutedEventArgs e) { CloseScreen.Close(); }