From 04dd654572fc70b50cae6a28392a45f439e3cbd9 Mon Sep 17 00:00:00 2001 From: Lev Rusanov <30170278+JDM170@users.noreply.github.com> Date: Mon, 9 Jun 2025 20:12:01 +0700 Subject: [PATCH] Update 1 Signed-off-by: Lev Rusanov <30170278+JDM170@users.noreply.github.com> --- MainForm.cs | 27 +++++++++- ResultForm.Designer.cs | 100 ++++++++++++++++++++++++++++++++++ ResultForm.cs | 33 ++++++++++++ ResultForm.resx | 120 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 279 insertions(+), 1 deletion(-) create mode 100644 ResultForm.Designer.cs create mode 100644 ResultForm.cs create mode 100644 ResultForm.resx diff --git a/MainForm.cs b/MainForm.cs index 1e67a28..ba63447 100644 --- a/MainForm.cs +++ b/MainForm.cs @@ -18,7 +18,18 @@ namespace ScreenCaptureApp { if (captureForm.ShowDialog() == DialogResult.OK) { - SaveImage(captureForm.CapturedImage); + // Добавляем кнопки для выбора действия + using (var resultForm = new ResultForm(captureForm.CapturedImage)) + { + if (resultForm.ShowDialog() == DialogResult.OK) + { + SaveImage(captureForm.CapturedImage); + } + else if (resultForm.DialogResult == DialogResult.Yes) + { + CopyToClipboard(captureForm.CapturedImage); + } + } } } this.Show(); @@ -35,10 +46,24 @@ namespace ScreenCaptureApp if (sfd.ShowDialog() == DialogResult.OK) { image.Save(sfd.FileName, GetImageFormat(sfd.FileName)); + MessageBox.Show("Screenshot saved successfully!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); } } } + private void CopyToClipboard(Image image) + { + try + { + Clipboard.SetImage(image); + MessageBox.Show("Screenshot copied to clipboard!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + catch (Exception ex) + { + MessageBox.Show($"Failed to copy to clipboard: {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private System.Drawing.Imaging.ImageFormat GetImageFormat(string fileName) { string ext = System.IO.Path.GetExtension(fileName).ToLower(); diff --git a/ResultForm.Designer.cs b/ResultForm.Designer.cs new file mode 100644 index 0000000..ca599ca --- /dev/null +++ b/ResultForm.Designer.cs @@ -0,0 +1,100 @@ +namespace ScreenCaptureApp +{ + partial class ResultForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.pictureBox1 = new System.Windows.Forms.PictureBox(); + this.btnSave = new System.Windows.Forms.Button(); + this.btnCopy = new System.Windows.Forms.Button(); + this.btnCancel = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit(); + this.SuspendLayout(); + // + // pictureBox1 + // + this.pictureBox1.Location = new System.Drawing.Point(12, 12); + this.pictureBox1.Name = "pictureBox1"; + this.pictureBox1.Size = new System.Drawing.Size(716, 346); + this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom; + this.pictureBox1.TabIndex = 0; + this.pictureBox1.TabStop = false; + // + // btnSave + // + this.btnSave.Location = new System.Drawing.Point(491, 364); + this.btnSave.Name = "btnSave"; + this.btnSave.Size = new System.Drawing.Size(75, 23); + this.btnSave.TabIndex = 1; + this.btnSave.Text = "Save"; + this.btnSave.UseVisualStyleBackColor = true; + this.btnSave.Click += new System.EventHandler(this.btnSave_Click); + // + // btnCopy + // + this.btnCopy.Location = new System.Drawing.Point(572, 364); + this.btnCopy.Name = "btnCopy"; + this.btnCopy.Size = new System.Drawing.Size(75, 23); + this.btnCopy.TabIndex = 2; + this.btnCopy.Text = "Copy"; + this.btnCopy.UseVisualStyleBackColor = true; + this.btnCopy.Click += new System.EventHandler(this.btnCopy_Click); + // + // btnCancel + // + this.btnCancel.Location = new System.Drawing.Point(653, 364); + this.btnCancel.Name = "btnCancel"; + this.btnCancel.Size = new System.Drawing.Size(75, 23); + this.btnCancel.TabIndex = 3; + this.btnCancel.Text = "Cancel"; + this.btnCancel.UseVisualStyleBackColor = true; + this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click); + // + // ResultForm + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(737, 396); + this.Controls.Add(this.btnCancel); + this.Controls.Add(this.btnCopy); + this.Controls.Add(this.btnSave); + this.Controls.Add(this.pictureBox1); + this.Name = "ResultForm"; + this.Text = "ResultForm"; + ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.PictureBox pictureBox1; + private System.Windows.Forms.Button btnSave; + private System.Windows.Forms.Button btnCopy; + private System.Windows.Forms.Button btnCancel; + } +} \ No newline at end of file diff --git a/ResultForm.cs b/ResultForm.cs new file mode 100644 index 0000000..54ecb86 --- /dev/null +++ b/ResultForm.cs @@ -0,0 +1,33 @@ +using System; +using System.Drawing; +using System.Windows.Forms; + +namespace ScreenCaptureApp +{ + public partial class ResultForm : Form + { + public ResultForm(Image capturedImage) + { + InitializeComponent(); + pictureBox1.Image = capturedImage; + } + + private void btnSave_Click(object sender, EventArgs e) + { + this.DialogResult = DialogResult.OK; + this.Close(); + } + + private void btnCopy_Click(object sender, EventArgs e) + { + this.DialogResult = DialogResult.Yes; + this.Close(); + } + + private void btnCancel_Click(object sender, EventArgs e) + { + this.DialogResult = DialogResult.Cancel; + this.Close(); + } + } +} \ No newline at end of file diff --git a/ResultForm.resx b/ResultForm.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/ResultForm.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file