From 97ca11117ff7b576941475e198fdcf59c0972830 Mon Sep 17 00:00:00 2001 From: Tarasovych Date: Mon, 8 Jan 2018 00:13:47 +0200 Subject: [PATCH] Added button to open screenshots folder --- CaptureSave/CaptureSave.Designer.cs | 15 ++++++++++++++- CaptureSave/CaptureSave.cs | 19 +++++++++++++++---- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/CaptureSave/CaptureSave.Designer.cs b/CaptureSave/CaptureSave.Designer.cs index 7678d5f..332991a 100644 --- a/CaptureSave/CaptureSave.Designer.cs +++ b/CaptureSave/CaptureSave.Designer.cs @@ -33,6 +33,7 @@ private void InitializeComponent() this.textScreenHeight = new System.Windows.Forms.TextBox(); this.labelHotkey = new System.Windows.Forms.Label(); this.textHotkey = new System.Windows.Forms.TextBox(); + this.buttonOpenFolder = new System.Windows.Forms.Button(); this.SuspendLayout(); // // labelScreenResolution @@ -79,11 +80,22 @@ private void InitializeComponent() this.textHotkey.Size = new System.Drawing.Size(106, 20); this.textHotkey.TabIndex = 4; // + // buttonOpenFolder + // + this.buttonOpenFolder.Location = new System.Drawing.Point(129, 30); + this.buttonOpenFolder.Name = "buttonOpenFolder"; + this.buttonOpenFolder.Size = new System.Drawing.Size(75, 64); + this.buttonOpenFolder.TabIndex = 5; + this.buttonOpenFolder.Text = "Open Folder"; + this.buttonOpenFolder.UseVisualStyleBackColor = true; + this.buttonOpenFolder.Click += new System.EventHandler(this.buttonOpenFolder_Click); + // // CaptureSave // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(144, 111); + this.ClientSize = new System.Drawing.Size(219, 111); + this.Controls.Add(this.buttonOpenFolder); this.Controls.Add(this.textHotkey); this.Controls.Add(this.labelHotkey); this.Controls.Add(this.textScreenHeight); @@ -104,6 +116,7 @@ private void InitializeComponent() private System.Windows.Forms.TextBox textScreenHeight; private System.Windows.Forms.Label labelHotkey; private System.Windows.Forms.TextBox textHotkey; + private System.Windows.Forms.Button buttonOpenFolder; } } diff --git a/CaptureSave/CaptureSave.cs b/CaptureSave/CaptureSave.cs index f3423b8..262d755 100644 --- a/CaptureSave/CaptureSave.cs +++ b/CaptureSave/CaptureSave.cs @@ -1,6 +1,7 @@ using System; using System.Drawing; using System.Drawing.Imaging; +using System.IO; using System.Runtime.InteropServices; using System.Windows.Forms; @@ -9,7 +10,6 @@ namespace CaptureSave public partial class CaptureSave : Form { - // DLL libraries used to manage hotkeys [DllImport("user32.dll")] public static extern bool RegisterHotKey(IntPtr hWnd, int id, int fsModifiers, int vlc); [DllImport("user32.dll")] @@ -20,12 +20,14 @@ public partial class CaptureSave : Form private int screenWidth = Convert.ToInt32(Screen.PrimaryScreen.Bounds.Width); private int screenHeight = Convert.ToInt32(Screen.PrimaryScreen.Bounds.Height); + private string filePath = AppDomain.CurrentDomain.BaseDirectory + "\\img\\"; + public CaptureSave() { InitializeComponent(); LoadResolution(); LoadHotkey(); - RegisterHotKey(this.Handle, MYACTION_HOTKEY_ID, 3, (int)Keys.S); + RegisterHotKey(this.Handle, MYACTION_HOTKEY_ID, 5, (int)Keys.S); } public void LoadResolution() @@ -50,8 +52,6 @@ protected override void WndProc(ref Message m) g.CopyFromScreen(0, 0, 0, 0, bitmap.Size); } - string filePath = AppDomain.CurrentDomain.BaseDirectory + "\\img\\"; - System.IO.FileInfo file = new System.IO.FileInfo(filePath); file.Directory.Create(); @@ -61,5 +61,16 @@ protected override void WndProc(ref Message m) } base.WndProc(ref m); } + + private void buttonOpenFolder_Click(object sender, EventArgs e) + { + if (Directory.Exists(filePath)) + { + System.Diagnostics.Process.Start(filePath); + } else + { + MessageBox.Show("Try to make screenshots first.", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } } }