From 34296694ec7cbf118716518503d42d8b16ec8e8d Mon Sep 17 00:00:00 2001 From: Lev Rusanov <30170278+JDM170@users.noreply.github.com> Date: Mon, 9 Jun 2025 20:24:51 +0700 Subject: [PATCH] Update 3 Signed-off-by: Lev Rusanov <30170278+JDM170@users.noreply.github.com> --- MainForm.Designer.cs | 21 +++++++++++---------- MainForm.cs | 37 +++++++++++++++++++++++++++++++++---- 2 files changed, 44 insertions(+), 14 deletions(-) diff --git a/MainForm.Designer.cs b/MainForm.Designer.cs index fc612a3..ce878cf 100644 --- a/MainForm.Designer.cs +++ b/MainForm.Designer.cs @@ -32,8 +32,8 @@ System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(MainForm)); this.notifyIcon1 = new System.Windows.Forms.NotifyIcon(this.components); this.contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(this.components); - this.toggleHotkeyToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.showToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.toggleHotkeyToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator(); this.exitToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.contextMenuStrip1.SuspendLayout(); @@ -45,7 +45,7 @@ this.notifyIcon1.Icon = ((System.Drawing.Icon)(resources.GetObject("notifyIcon1.Icon"))); this.notifyIcon1.Text = "notifyIcon1"; this.notifyIcon1.Visible = true; - this.notifyIcon1.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(this.notifyIcon1_MouseDoubleClick); + this.notifyIcon1.MouseClick += new System.Windows.Forms.MouseEventHandler(this.notifyIcon1_MouseClick); // // contextMenuStrip1 // @@ -55,14 +55,7 @@ this.toolStripSeparator1, this.exitToolStripMenuItem}); this.contextMenuStrip1.Name = "contextMenuStrip1"; - this.contextMenuStrip1.Size = new System.Drawing.Size(222, 98); - // - // toggleHotkeyToolStripMenuItem - // - this.toggleHotkeyToolStripMenuItem.Name = "toggleHotkeyToolStripMenuItem"; - this.toggleHotkeyToolStripMenuItem.Size = new System.Drawing.Size(221, 22); - this.toggleHotkeyToolStripMenuItem.Text = "Disable Print Screen capture"; - this.toggleHotkeyToolStripMenuItem.Click += new System.EventHandler(this.toggleHotkeyToolStripMenuItem_Click); + this.contextMenuStrip1.Size = new System.Drawing.Size(222, 76); // // showToolStripMenuItem // @@ -71,6 +64,13 @@ this.showToolStripMenuItem.Text = "Show in Taskbar"; this.showToolStripMenuItem.Click += new System.EventHandler(this.showToolStripMenuItem_Click); // + // toggleHotkeyToolStripMenuItem + // + this.toggleHotkeyToolStripMenuItem.Name = "toggleHotkeyToolStripMenuItem"; + this.toggleHotkeyToolStripMenuItem.Size = new System.Drawing.Size(221, 22); + this.toggleHotkeyToolStripMenuItem.Text = "Disable Print Screen capture"; + this.toggleHotkeyToolStripMenuItem.Click += new System.EventHandler(this.toggleHotkeyToolStripMenuItem_Click); + // // toolStripSeparator1 // this.toolStripSeparator1.Name = "toolStripSeparator1"; @@ -92,6 +92,7 @@ this.Name = "MainForm"; this.Text = "MainForm"; this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.MainForm_FormClosing); + this.Resize += new System.EventHandler(this.MainForm_Resize); this.contextMenuStrip1.ResumeLayout(false); this.ResumeLayout(false); diff --git a/MainForm.cs b/MainForm.cs index 9019aa2..fac53f9 100644 --- a/MainForm.cs +++ b/MainForm.cs @@ -114,29 +114,58 @@ namespace ScreenCaptureApp private void MainForm_FormClosing(object sender, FormClosingEventArgs e) { UnregisterHotKey(this.Handle, PRINT_SCREEN_ID); + notifyIcon1.Visible = false; + notifyIcon1.Dispose(); } - private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e) + private void notifyIcon1_MouseClick(object sender, MouseEventArgs e) { - this.WindowState = FormWindowState.Normal; - this.ShowInTaskbar = true; + if (e.Button == MouseButtons.Right) + { + // Показываем контекстное меню + MethodInvoker mi = new MethodInvoker(() => { + notifyIcon1.ContextMenuStrip.Show(Cursor.Position); + }); + this.BeginInvoke(mi); + } + else if (e.Button == MouseButtons.Left) + { + // Левый клик - показываем основное окно + this.WindowState = FormWindowState.Normal; + this.ShowInTaskbar = true; + this.Show(); + } } private void showToolStripMenuItem_Click(object sender, EventArgs e) { this.WindowState = FormWindowState.Normal; this.ShowInTaskbar = true; + this.Show(); } private void exitToolStripMenuItem_Click(object sender, EventArgs e) { + notifyIcon1.Visible = false; Application.Exit(); } private void toggleHotkeyToolStripMenuItem_Click(object sender, EventArgs e) { captureOnKeyPress = !captureOnKeyPress; - toggleHotkeyToolStripMenuItem.Text = captureOnKeyPress ? "Disable Print Screen capture" : "Enable Print Screen capture"; + var item = (ToolStripMenuItem)sender; + item.Text = captureOnKeyPress ? "Disable Print Screen capture" : "Enable Print Screen capture"; + notifyIcon1.ShowBalloonTip(1000, "Screen Capture", + captureOnKeyPress ? "Print Screen capture enabled" : "Print Screen capture disabled", + ToolTipIcon.Info); + } + + private void MainForm_Resize(object sender, EventArgs e) + { + if (this.WindowState == FormWindowState.Minimized) + { + this.ShowInTaskbar = false; + } } } } \ No newline at end of file