Signed-off-by: Lev Rusanov <30170278+JDM170@users.noreply.github.com>
This commit is contained in:
2025-06-09 20:24:51 +07:00
parent cdb14d6639
commit 34296694ec
2 changed files with 44 additions and 14 deletions

21
MainForm.Designer.cs generated
View File

@@ -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);

View File

@@ -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;
}
}
}
}