diff --git a/App.config b/App.config index 193aecc..77b6043 100644 --- a/App.config +++ b/App.config @@ -1,6 +1,18 @@  + + +
+ + + + + + + + + \ No newline at end of file diff --git a/RecycleBinHandle.cs b/RecycleBinHandle.cs index bad028f..8576dbd 100644 --- a/RecycleBinHandle.cs +++ b/RecycleBinHandle.cs @@ -21,6 +21,8 @@ public class RecycleBinHandle : Form [DllImport("shell32.dll")] private static extern int SHEmptyRecycleBin(IntPtr handle, string root, int flags); + + private static Shqueryrbinfo shqueryrbinfo; [DllImport("shell32.dll")] private static extern int SHQueryRecycleBin(string pszRootPath, ref Shqueryrbinfo queryInfo); @@ -35,7 +37,6 @@ private struct Shqueryrbinfo public static int GetCount() { - Shqueryrbinfo shqueryrbinfo = new Shqueryrbinfo(); shqueryrbinfo.cbSize = Marshal.SizeOf(typeof(Shqueryrbinfo)); SHQueryRecycleBin(string.Empty, ref shqueryrbinfo); return (int) shqueryrbinfo.i64NumItems; diff --git a/Tray.cs b/Tray.cs index cf78b1f..f6e98c0 100644 --- a/Tray.cs +++ b/Tray.cs @@ -1,6 +1,5 @@ using System; using System.Diagnostics; -using System.Drawing; using System.Windows.Forms; namespace RecycleBin @@ -11,6 +10,7 @@ public class Tray private NotifyIcon _notifyIcon; private readonly RecycleBinHandle _recycleBinHandle; private bool _recycleBinIsEmpty = true; + private TrayContextMenu _trayContextMenu = new TrayContextMenu(); public Tray() { @@ -36,29 +36,24 @@ public void CreateTrayIcon() var openMenuItem = new ToolStripMenuItem("打开回收站", null, _recycleBinHandle.Open); var clearMenuItem = new ToolStripMenuItem("清空回收站", null, _recycleBinHandle.Clear); var exitMenuItem = new ToolStripMenuItem("退出", null, TrayExit); - var settingsMenuItem = new ToolStripMenuItem("设置", null, (sender, e) => - { - var form = new Form {FormBorderStyle = FormBorderStyle.FixedDialog, - Location = new Point(10, 10)}; - form.Show(); - }); - + // var settingsMenuItem = new ToolStripMenuItem("设置", null, (sender, e) => + // { + // if (_trayContextMenu == null) + // { + // _trayContextMenu = new TrayContextMenu(); + // } + // _trayContextMenu.Visible = true; + // }); + // // 添加菜单 var contextMenuStrip = new ContextMenuStrip(); - contextMenuStrip.Items.Add(settingsMenuItem); + // contextMenuStrip.Items.Add(settingsMenuItem); contextMenuStrip.Items.Add(openMenuItem); contextMenuStrip.Items.Add(clearMenuItem); contextMenuStrip.Items.Add(exitMenuItem); // 设置右键菜单 _notifyIcon.ContextMenuStrip = contextMenuStrip; - // _notifyIcon.MouseClick += (sender, e) => - // { - // var form = new Form {FormBorderStyle = FormBorderStyle.FixedDialog, - // Location = Control.MousePosition}; - // form.Show(); - // }; - // 托盘图标添加鼠标双击事件 _notifyIcon.MouseDoubleClick += (sender, e) => { diff --git a/TrayContextMenu.cs b/TrayContextMenu.cs index b50a1e0..9739e89 100644 --- a/TrayContextMenu.cs +++ b/TrayContextMenu.cs @@ -7,11 +7,81 @@ namespace RecycleBin /// public class TrayContextMenu : Form { + private Button button1; + private Button button2; + private Button button4; + private Button button3; + public TrayContextMenu() { - + InitializeComponent(); + Visible = false; + } + + private void InitializeComponent() + { + button1 = new Button(); + button2 = new Button(); + button3 = new Button(); + button4 = new Button(); + SuspendLayout(); + // + // button1 + // + button1.Location = new System.Drawing.Point(1, 1); + button1.Name = "button1"; + button1.Size = new System.Drawing.Size(75, 23); + button1.TabIndex = 1; + button1.Text = "设置"; + button1.UseVisualStyleBackColor = true; + button1.Click += button1_Click; + // + // button2 + // + button2.Location = new System.Drawing.Point(1, 30); + button2.Name = "button2"; + button2.Size = new System.Drawing.Size(75, 23); + button2.TabIndex = 2; + button2.Text = "打开回收站"; + button2.UseVisualStyleBackColor = true; + // + // button3 + // + button3.Location = new System.Drawing.Point(1, 59); + button3.Name = "button3"; + button3.Size = new System.Drawing.Size(75, 23); + button3.TabIndex = 3; + button3.Text = "清空回收站"; + button3.UseVisualStyleBackColor = true; + // + // button4 + // + button4.Location = new System.Drawing.Point(1, 88); + button4.Name = "button4"; + button4.Size = new System.Drawing.Size(75, 23); + button4.TabIndex = 4; + button4.Text = "退出"; + button4.UseVisualStyleBackColor = true; + // + // TrayContextMenu + // + ClientSize = new System.Drawing.Size(77, 112); + Controls.Add(button4); + Controls.Add(button3); + Controls.Add(button2); + Controls.Add(button1); + FormBorderStyle = FormBorderStyle.None; + Name = "TrayContextMenu"; + Load += TrayContextMenu_Load; + ResumeLayout(false); + } + + private void button1_Click(object sender, System.EventArgs e) + { + } + + private void TrayContextMenu_Load(object sender, System.EventArgs e) + { } - - } } \ No newline at end of file