diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..93621e5 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +.vs +bin/ +obj/ +packages/ +*.csproj.user diff --git a/App.config b/App.config new file mode 100644 index 0000000..193aecc --- /dev/null +++ b/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/MainForm.Designer.cs b/MainForm.Designer.cs new file mode 100644 index 0000000..3859d95 --- /dev/null +++ b/MainForm.Designer.cs @@ -0,0 +1,62 @@ +namespace ScreenCaptureApp +{ + partial class MainForm + { + /// + /// Обязательная переменная конструктора. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Освободить все используемые ресурсы. + /// + /// истинно, если управляемый ресурс должен быть удален; иначе ложно. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Код, автоматически созданный конструктором форм Windows + + /// + /// Требуемый метод для поддержки конструктора — не изменяйте + /// содержимое этого метода с помощью редактора кода. + /// + private void InitializeComponent() + { + this.bigButton = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // bigButton + // + this.bigButton.Font = new System.Drawing.Font("Microsoft Sans Serif", 26.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204))); + this.bigButton.Location = new System.Drawing.Point(12, 12); + this.bigButton.Name = "bigButton"; + this.bigButton.Size = new System.Drawing.Size(314, 163); + this.bigButton.TabIndex = 2; + this.bigButton.Text = "SHOOOOOT"; + this.bigButton.UseVisualStyleBackColor = true; + this.bigButton.Click += new System.EventHandler(this.btnCapture_Click); + // + // MainForm + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(339, 186); + this.Controls.Add(this.bigButton); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; + this.Name = "MainForm"; + this.Text = "MainForm"; + this.ResumeLayout(false); + + } + + #endregion + private System.Windows.Forms.Button bigButton; + } +} + diff --git a/MainForm.cs b/MainForm.cs new file mode 100644 index 0000000..1e67a28 --- /dev/null +++ b/MainForm.cs @@ -0,0 +1,54 @@ +using System; +using System.Drawing; +using System.Windows.Forms; + +namespace ScreenCaptureApp +{ + public partial class MainForm : Form + { + public MainForm() + { + InitializeComponent(); + } + + private void btnCapture_Click(object sender, EventArgs e) + { + this.Hide(); + using (var captureForm = new ScreenCaptureForm()) + { + if (captureForm.ShowDialog() == DialogResult.OK) + { + SaveImage(captureForm.CapturedImage); + } + } + this.Show(); + } + + private void SaveImage(Image image) + { + using (SaveFileDialog sfd = new SaveFileDialog()) + { + sfd.Filter = "PNG Image|*.png|JPEG Image|*.jpg|Bitmap Image|*.bmp"; + sfd.Title = "Save Screenshot"; + sfd.FileName = "screenshot.png"; + + if (sfd.ShowDialog() == DialogResult.OK) + { + image.Save(sfd.FileName, GetImageFormat(sfd.FileName)); + } + } + } + + private System.Drawing.Imaging.ImageFormat GetImageFormat(string fileName) + { + string ext = System.IO.Path.GetExtension(fileName).ToLower(); + switch (ext) + { + case ".jpg": return System.Drawing.Imaging.ImageFormat.Jpeg; + case ".jpeg": return System.Drawing.Imaging.ImageFormat.Jpeg; + case ".bmp": return System.Drawing.Imaging.ImageFormat.Bmp; + default: return System.Drawing.Imaging.ImageFormat.Png; + } + } + } +} \ No newline at end of file diff --git a/MainForm.resx b/MainForm.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/MainForm.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 diff --git a/Program.cs b/Program.cs new file mode 100644 index 0000000..0cd8a2f --- /dev/null +++ b/Program.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace ScreenCaptureApp +{ + internal static class Program + { + /// + /// Главная точка входа для приложения. + /// + [STAThread] + static void Main() + { + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new MainForm()); + } + } +} diff --git a/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..04c3bfd --- /dev/null +++ b/Properties/AssemblyInfo.cs @@ -0,0 +1,33 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// Общие сведения об этой сборке предоставляются следующим набором +// набора атрибутов. Измените значения этих атрибутов для изменения сведений, +// связанных со сборкой. +[assembly: AssemblyTitle("ScreenCaptureApp")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("ScreenCaptureApp")] +[assembly: AssemblyCopyright("Lev Rusanov © 2025")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Установка значения False для параметра ComVisible делает типы в этой сборке невидимыми +// для компонентов COM. Если необходимо обратиться к типу в этой сборке через +// COM, следует установить атрибут ComVisible в TRUE для этого типа. +[assembly: ComVisible(false)] + +// Следующий GUID служит для идентификации библиотеки типов, если этот проект будет видимым для COM +[assembly: Guid("f223b7c1-818f-499a-84e4-0fc93cf930db")] + +// Сведения о версии сборки состоят из указанных ниже четырех значений: +// +// Основной номер версии +// Дополнительный номер версии +// Номер сборки +// Редакция +// +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Properties/Resources.Designer.cs b/Properties/Resources.Designer.cs new file mode 100644 index 0000000..ae58335 --- /dev/null +++ b/Properties/Resources.Designer.cs @@ -0,0 +1,63 @@ +//------------------------------------------------------------------------------ +// +// Этот код создан программой. +// Исполняемая версия:4.0.30319.42000 +// +// Изменения в этом файле могут привести к неправильной работе и будут потеряны в случае +// повторной генерации кода. +// +//------------------------------------------------------------------------------ + +namespace ScreenCaptureApp.Properties { + using System; + + + /// + /// Класс ресурса со строгой типизацией для поиска локализованных строк и т.д. + /// + // Этот класс создан автоматически классом StronglyTypedResourceBuilder + // с помощью такого средства, как ResGen или Visual Studio. + // Чтобы добавить или удалить член, измените файл .ResX и снова запустите ResGen + // с параметром /str или перестройте свой проект VS. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() { + } + + /// + /// Возвращает кэшированный экземпляр ResourceManager, использованный этим классом. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("ScreenCaptureApp.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Перезаписывает свойство CurrentUICulture текущего потока для всех + /// обращений к ресурсу с помощью этого класса ресурса со строгой типизацией. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + } +} diff --git a/Properties/Resources.resx b/Properties/Resources.resx new file mode 100644 index 0000000..af7dbeb --- /dev/null +++ b/Properties/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Properties/Settings.Designer.cs b/Properties/Settings.Designer.cs new file mode 100644 index 0000000..0011b21 --- /dev/null +++ b/Properties/Settings.Designer.cs @@ -0,0 +1,26 @@ +//------------------------------------------------------------------------------ +// +// Этот код создан программой. +// Исполняемая версия:4.0.30319.42000 +// +// Изменения в этом файле могут привести к неправильной работе и будут потеряны в случае +// повторной генерации кода. +// +//------------------------------------------------------------------------------ + +namespace ScreenCaptureApp.Properties { + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.14.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default { + get { + return defaultInstance; + } + } + } +} diff --git a/Properties/Settings.settings b/Properties/Settings.settings new file mode 100644 index 0000000..3964565 --- /dev/null +++ b/Properties/Settings.settings @@ -0,0 +1,7 @@ + + + + + + + diff --git a/ScreenCaptureApp.csproj b/ScreenCaptureApp.csproj new file mode 100644 index 0000000..1b83899 --- /dev/null +++ b/ScreenCaptureApp.csproj @@ -0,0 +1,102 @@ + + + + + Debug + AnyCPU + {F223B7C1-818F-499A-84E4-0FC93CF930DB} + WinExe + ScreenCaptureApp + ScreenCaptureApp + v4.8 + 512 + true + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + Form + + + ResultForm.cs + + + Form + + + ScreenCaptureForm.cs + + + ResultForm.cs + + + Form + + + MainForm.cs + + + + + MainForm.cs + + + ResXFileCodeGenerator + Resources.Designer.cs + Designer + + + True + Resources.resx + True + + + ScreenCaptureForm.cs + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + True + Settings.settings + True + + + + + + + \ No newline at end of file diff --git a/ScreenCaptureApp.sln b/ScreenCaptureApp.sln new file mode 100644 index 0000000..b8e957e --- /dev/null +++ b/ScreenCaptureApp.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.14.36202.13 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ScreenCaptureApp", "ScreenCaptureApp.csproj", "{F223B7C1-818F-499A-84E4-0FC93CF930DB}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {F223B7C1-818F-499A-84E4-0FC93CF930DB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F223B7C1-818F-499A-84E4-0FC93CF930DB}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F223B7C1-818F-499A-84E4-0FC93CF930DB}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F223B7C1-818F-499A-84E4-0FC93CF930DB}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {B6FEAF19-190F-4746-A923-9EBC765A7328} + EndGlobalSection +EndGlobal diff --git a/ScreenCaptureForm.Designer.cs b/ScreenCaptureForm.Designer.cs new file mode 100644 index 0000000..81dc459 --- /dev/null +++ b/ScreenCaptureForm.Designer.cs @@ -0,0 +1,46 @@ +namespace ScreenCaptureApp +{ + partial class ScreenCaptureForm + { + /// + /// 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.SuspendLayout(); + // + // ScreenCaptureForm + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(430, 167); + this.Name = "ScreenCaptureForm"; + this.Text = "ScreenCaptureForm"; + this.ResumeLayout(false); + + } + + #endregion + } +} \ No newline at end of file diff --git a/ScreenCaptureForm.cs b/ScreenCaptureForm.cs new file mode 100644 index 0000000..b7e00c7 --- /dev/null +++ b/ScreenCaptureForm.cs @@ -0,0 +1,148 @@ +using System; +using System.Drawing; +using System.Drawing.Imaging; +using System.Windows.Forms; + +namespace ScreenCaptureApp +{ + public partial class ScreenCaptureForm : Form + { + private Point startPoint; + private Point endPoint; + private bool isSelecting = false; + private Bitmap screenBitmap; + private Rectangle selectedRegion; + + public Image CapturedImage { get; private set; } + + public ScreenCaptureForm() + { + InitializeComponent(); + InitializeCaptureForm(); + } + + private void InitializeCaptureForm() + { + this.FormBorderStyle = FormBorderStyle.None; + this.WindowState = FormWindowState.Maximized; + this.Opacity = 0.3; + this.DoubleBuffered = true; + this.Cursor = Cursors.Cross; + this.KeyPreview = true; + + // Создаем скриншот всего экрана + CaptureScreen(); + } + + private void CaptureScreen() + { + screenBitmap = new Bitmap(Screen.PrimaryScreen.Bounds.Width, + Screen.PrimaryScreen.Bounds.Height, + PixelFormat.Format32bppArgb); + + using (Graphics g = Graphics.FromImage(screenBitmap)) + { + g.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, + Screen.PrimaryScreen.Bounds.Y, + 0, 0, + Screen.PrimaryScreen.Bounds.Size, + CopyPixelOperation.SourceCopy); + } + + this.BackgroundImage = screenBitmap; + } + + protected override void OnMouseDown(MouseEventArgs e) + { + if (e.Button == MouseButtons.Left) + { + startPoint = e.Location; + isSelecting = true; + } + base.OnMouseDown(e); + } + + protected override void OnMouseMove(MouseEventArgs e) + { + if (isSelecting) + { + endPoint = e.Location; + this.Invalidate(); // Перерисовываем форму + } + base.OnMouseMove(e); + } + + protected override void OnMouseUp(MouseEventArgs e) + { + if (e.Button == MouseButtons.Left && isSelecting) + { + endPoint = e.Location; + isSelecting = false; + CaptureSelectedRegion(); + } + base.OnMouseUp(e); + } + + protected override void OnPaint(PaintEventArgs e) + { + if (isSelecting) + { + using (Pen pen = new Pen(Color.Red, 2)) + { + Rectangle rect = GetSelectionRectangle(); + e.Graphics.DrawRectangle(pen, rect); + + // Рисуем перекрестие для точного выбора + e.Graphics.DrawLine(pen, new Point(rect.X, rect.Y + rect.Height / 2), + new Point(rect.X + rect.Width, rect.Y + rect.Height / 2)); + e.Graphics.DrawLine(pen, new Point(rect.X + rect.Width / 2, rect.Y), + new Point(rect.X + rect.Width / 2, rect.Y + rect.Height)); + } + } + base.OnPaint(e); + } + + private Rectangle GetSelectionRectangle() + { + return new Rectangle( + Math.Min(startPoint.X, endPoint.X), + Math.Min(startPoint.Y, endPoint.Y), + Math.Abs(startPoint.X - endPoint.X), + Math.Abs(startPoint.Y - endPoint.Y)); + } + + private void CaptureSelectedRegion() + { + selectedRegion = GetSelectionRectangle(); + + if (selectedRegion.Width <= 0 || selectedRegion.Height <= 0) + { + this.DialogResult = DialogResult.Cancel; + return; + } + + // Вырезаем выбранную область + CapturedImage = new Bitmap(selectedRegion.Width, selectedRegion.Height); + + using (Graphics g = Graphics.FromImage(CapturedImage)) + { + g.DrawImage(screenBitmap, new Rectangle(0, 0, selectedRegion.Width, selectedRegion.Height), + selectedRegion, + GraphicsUnit.Pixel); + } + + this.DialogResult = DialogResult.OK; + this.Close(); + } + + protected override void OnKeyDown(KeyEventArgs e) + { + if (e.KeyCode == Keys.Escape) + { + this.DialogResult = DialogResult.Cancel; + this.Close(); + } + base.OnKeyDown(e); + } + } +} \ No newline at end of file diff --git a/ScreenCaptureForm.resx b/ScreenCaptureForm.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/ScreenCaptureForm.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