添加最小化到托盘
This commit is contained in:
commit
5d1a6af9a9
3 files changed
+49
No files matched your search
@@ -1,8 +1,10 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Data.SqlClient;
|
||||
using System.Diagnostics;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
@@ -11,6 +13,7 @@ using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Forms;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Animation;
|
||||
@@ -29,6 +32,45 @@ namespace ProcessManageUI
|
||||
/// </summary>
|
||||
public partial class MainWindow : Window
|
||||
{
|
||||
private readonly System.Windows.Forms.NotifyIcon nIcon = new System.Windows.Forms.NotifyIcon();
|
||||
private void initNotifyIcon()
|
||||
{
|
||||
nIcon.Visible = true;
|
||||
nIcon.Icon = new Icon("./sunlight_logo.ico");
|
||||
nIcon.Text = "测试程序";
|
||||
nIcon.MouseClick += new System.Windows.Forms.MouseEventHandler(show_Click);
|
||||
nIcon.ContextMenu = new System.Windows.Forms.ContextMenu();
|
||||
System.Windows.Forms.MenuItem show = new System.Windows.Forms.MenuItem("打开");
|
||||
show.Click += new EventHandler(show_Click);
|
||||
nIcon.ContextMenu.MenuItems.Add(show);
|
||||
System.Windows.Forms.MenuItem exit = new System.Windows.Forms.MenuItem("退出");
|
||||
exit.Click += new EventHandler(exit_Click);
|
||||
nIcon.ContextMenu.MenuItems.Add(exit);
|
||||
}
|
||||
private void exit_Click(object sender, EventArgs e)
|
||||
{
|
||||
Environment.Exit(0);
|
||||
}
|
||||
private void show_Click(object Sender, EventArgs e)
|
||||
{
|
||||
if (WindowState == WindowState.Minimized)
|
||||
WindowState = WindowState.Normal;
|
||||
Show();
|
||||
Activate();
|
||||
}
|
||||
protected override void OnStateChanged(EventArgs e)
|
||||
{
|
||||
if (WindowState == WindowState.Minimized) Hide();
|
||||
|
||||
base.OnStateChanged(e);
|
||||
}
|
||||
protected override void OnClosing(CancelEventArgs e)
|
||||
{
|
||||
e.Cancel = true;
|
||||
Hide();
|
||||
base.OnClosing(e);
|
||||
}
|
||||
|
||||
private static IniFile.IniFiles Configini = new IniFile.IniFiles(Convert.ToString(System.AppDomain.CurrentDomain.BaseDirectory) + "ProcessManageConfigini.ini");
|
||||
private static string SQLIP = Configini.IniReadvalue("SQL_SERVER", "SQL1"); //读配置文件
|
||||
private static string SQLNAME = Configini.IniReadvalue("SQL_SERVER", "SQL2");
|
||||
@@ -71,6 +113,8 @@ namespace ProcessManageUI
|
||||
Datalog.AppendText("\n设定循环时间"+ _intervalMs+"MS");
|
||||
disTimer.Tick += EXTask;
|
||||
disTimer.Start();//计时开始
|
||||
|
||||
initNotifyIcon();
|
||||
}
|
||||
|
||||
private void EXTask(object sender, EventArgs e)
|
||||
|
||||
@@ -37,6 +37,8 @@
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Drawing" />
|
||||
<Reference Include="System.Windows.Forms" />
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Core" />
|
||||
@@ -104,5 +106,8 @@
|
||||
<Version>1.0.119</Version>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Resource Include="sunlight_logo.ico" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 17 KiB |
Reference in new issue
Block a user