Update 4
Signed-off-by: Lev Rusanov <30170278+JDM170@users.noreply.github.com>
This commit is contained in:
2
MainForm.Designer.cs
generated
2
MainForm.Designer.cs
generated
@@ -91,8 +91,6 @@
|
|||||||
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
|
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
|
||||||
this.Name = "MainForm";
|
this.Name = "MainForm";
|
||||||
this.Text = "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.contextMenuStrip1.ResumeLayout(false);
|
||||||
this.ResumeLayout(false);
|
this.ResumeLayout(false);
|
||||||
|
|
||||||
|
|||||||
124
MainForm.cs
124
MainForm.cs
@@ -7,7 +7,6 @@ namespace ScreenCaptureApp
|
|||||||
{
|
{
|
||||||
public partial class MainForm : Form
|
public partial class MainForm : Form
|
||||||
{
|
{
|
||||||
// Импорт функции для регистрации горячих клавиш
|
|
||||||
[DllImport("user32.dll")]
|
[DllImport("user32.dll")]
|
||||||
private static extern bool RegisterHotKey(IntPtr hWnd, int id, int fsModifiers, int vk);
|
private static extern bool RegisterHotKey(IntPtr hWnd, int id, int fsModifiers, int vk);
|
||||||
|
|
||||||
@@ -22,8 +21,17 @@ namespace ScreenCaptureApp
|
|||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
RegisterHotkey();
|
RegisterHotkey();
|
||||||
this.WindowState = FormWindowState.Minimized;
|
this.Hide(); // Сразу скрываем основное окно
|
||||||
this.ShowInTaskbar = false;
|
}
|
||||||
|
|
||||||
|
private void ShowMainWindow()
|
||||||
|
{
|
||||||
|
if (this.WindowState == FormWindowState.Minimized)
|
||||||
|
{
|
||||||
|
this.WindowState = FormWindowState.Normal;
|
||||||
|
}
|
||||||
|
this.Show();
|
||||||
|
this.Activate();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void RegisterHotkey()
|
private void RegisterHotkey()
|
||||||
@@ -35,6 +43,13 @@ namespace ScreenCaptureApp
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void ExitApplication()
|
||||||
|
{
|
||||||
|
UnregisterHotKey(this.Handle, PRINT_SCREEN_ID);
|
||||||
|
notifyIcon1.Visible = false;
|
||||||
|
Application.Exit();
|
||||||
|
}
|
||||||
|
|
||||||
protected override void WndProc(ref Message m)
|
protected override void WndProc(ref Message m)
|
||||||
{
|
{
|
||||||
if (m.Msg == WM_HOTKEY && captureOnKeyPress)
|
if (m.Msg == WM_HOTKEY && captureOnKeyPress)
|
||||||
@@ -54,34 +69,37 @@ namespace ScreenCaptureApp
|
|||||||
{
|
{
|
||||||
if (captureForm.ShowDialog() == DialogResult.OK)
|
if (captureForm.ShowDialog() == DialogResult.OK)
|
||||||
{
|
{
|
||||||
using (var resultForm = new ResultForm(captureForm.CapturedImage))
|
ProcessCapturedImage(captureForm.CapturedImage);
|
||||||
{
|
|
||||||
if (resultForm.ShowDialog() == DialogResult.OK)
|
|
||||||
{
|
|
||||||
SaveImage(captureForm.CapturedImage);
|
|
||||||
}
|
|
||||||
else if (resultForm.DialogResult == DialogResult.Yes)
|
|
||||||
{
|
|
||||||
CopyToClipboard(captureForm.CapturedImage);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.Show();
|
this.Show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void ProcessCapturedImage(Image image)
|
||||||
|
{
|
||||||
|
using (var resultForm = new ResultForm(image))
|
||||||
|
{
|
||||||
|
var result = resultForm.ShowDialog();
|
||||||
|
if (result == DialogResult.OK)
|
||||||
|
{
|
||||||
|
SaveImage(image);
|
||||||
|
}
|
||||||
|
else if (result == DialogResult.Yes)
|
||||||
|
{
|
||||||
|
CopyToClipboard(image);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void SaveImage(Image image)
|
private void SaveImage(Image image)
|
||||||
{
|
{
|
||||||
using (SaveFileDialog sfd = new SaveFileDialog())
|
using (var sfd = new SaveFileDialog())
|
||||||
{
|
{
|
||||||
sfd.Filter = "PNG Image|*.png|JPEG Image|*.jpg|Bitmap Image|*.bmp";
|
sfd.Filter = "PNG Image|*.png|JPEG Image|*.jpg|Bitmap Image|*.bmp";
|
||||||
sfd.Title = "Save Screenshot";
|
|
||||||
sfd.FileName = "screenshot.png";
|
|
||||||
|
|
||||||
if (sfd.ShowDialog() == DialogResult.OK)
|
if (sfd.ShowDialog() == DialogResult.OK)
|
||||||
{
|
{
|
||||||
image.Save(sfd.FileName, GetImageFormat(sfd.FileName));
|
image.Save(sfd.FileName, GetImageFormat(sfd.FileName));
|
||||||
MessageBox.Show("Screenshot saved successfully!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
notifyIcon1.ShowBalloonTip(1000, "Success", "Screenshot saved!", ToolTipIcon.Info);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -91,11 +109,11 @@ namespace ScreenCaptureApp
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
Clipboard.SetImage(image);
|
Clipboard.SetImage(image);
|
||||||
MessageBox.Show("Screenshot copied to clipboard!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
notifyIcon1.ShowBalloonTip(1000, "Success", "Copied to clipboard!", ToolTipIcon.Info);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
MessageBox.Show($"Failed to copy to clipboard: {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
notifyIcon1.ShowBalloonTip(1000, "Error", $"Copy failed: {ex.Message}", ToolTipIcon.Error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -111,61 +129,35 @@ namespace ScreenCaptureApp
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
|
private void notifyIcon1_MouseClick(object sender, EventArgs e) => ShowMainWindow();
|
||||||
{
|
|
||||||
UnregisterHotKey(this.Handle, PRINT_SCREEN_ID);
|
|
||||||
notifyIcon1.Visible = false;
|
|
||||||
notifyIcon1.Dispose();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void notifyIcon1_MouseClick(object sender, MouseEventArgs e)
|
private void showToolStripMenuItem_Click(object sender, EventArgs e) => ShowMainWindow();
|
||||||
{
|
|
||||||
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)
|
private void toggleHotkeyToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
captureOnKeyPress = !captureOnKeyPress;
|
captureOnKeyPress = !captureOnKeyPress;
|
||||||
var item = (ToolStripMenuItem)sender;
|
var item = (ToolStripMenuItem)sender;
|
||||||
item.Text = captureOnKeyPress ? "Disable Print Screen capture" : "Enable Print Screen capture";
|
item.Text = $"Print Screen Capture: {(captureOnKeyPress ? "ON" : "OFF")}";
|
||||||
notifyIcon1.ShowBalloonTip(1000, "Screen Capture",
|
notifyIcon1.ShowBalloonTip(1000, "Hotkey",
|
||||||
captureOnKeyPress ? "Print Screen capture enabled" : "Print Screen capture disabled",
|
$"Print Screen capture {(captureOnKeyPress ? "enabled" : "disabled")}",
|
||||||
ToolTipIcon.Info);
|
ToolTipIcon.Info);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void MainForm_Resize(object sender, EventArgs e)
|
private void exitToolStripMenuItem_Click(Object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if (this.WindowState == FormWindowState.Minimized)
|
ExitApplication();
|
||||||
{
|
}
|
||||||
this.ShowInTaskbar = false;
|
|
||||||
}
|
protected override void OnLoad(EventArgs e)
|
||||||
|
{
|
||||||
|
base.OnLoad(e);
|
||||||
|
this.Hide(); // Гарантированно скрываем окно при загрузке
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnFormClosing(FormClosingEventArgs e)
|
||||||
|
{
|
||||||
|
base.OnFormClosing(e);
|
||||||
|
ExitApplication();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user