Exemplo n.º 1
0
        /// <summary>
        /// Handles the pause resume button click event.
        /// </summary>
        /// <param name="sender">Sender object.</param>
        /// <param name="e">Event arguments.</param>
        private void OnPauseResumeButtonClick(object sender, EventArgs e)
        {
            // Check if must pause
            if (this.pauseResumeButton.Text.StartsWith("&P", StringComparison.InvariantCulture))
            {
                // Disable keyboard hook
                KeyboardHook.DisableHook();

                // Update monitor status
                this.hotkeyGroupBox.Text = "Hotkey is: INACTIVE";

                // Set button text
                this.pauseResumeButton.Text = "&Resume";
            }
            else
            {
                // Enable keyboard hook
                KeyboardHook.EnableHook();

                // Update monitor status
                this.hotkeyGroupBox.Text = "Hotkey is: ACTIVE";

                // Set button text
                this.pauseResumeButton.Text = "&Pause";
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="T:PrintScreenToPaint.MainForm"/> class.
        /// </summary>
        public MainForm()
        {
            // The InitializeComponent() call is required for Windows Forms designer support.
            this.InitializeComponent();

            // Set notify icon
            this.mainNotifyIcon.Icon = this.Icon;

            // Set semantic version
            this.semanticVersion = this.assemblyVersion.Major + "." + this.assemblyVersion.Minor + "." + this.assemblyVersion.Build;

            // TODO Set current directory [can be made conditional to: args[1] == "/autostart"]
            Directory.SetCurrentDirectory(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location));

            // Set the target key press event handler
            KeyboardHook.TargetKeyPress += this.OnTargetKeyPress;

            // Enable the keyboard hook
            KeyboardHook.EnableHook();

            /* Process settings */

            // Check for settings data file
            if (!File.Exists(this.settingsFilePath))
            {
                // Not present, assume first run and create it
                this.SaveSettingsData();

                // Inform user
                MessageBox.Show($"Created \"{this.settingsFilePath}\" file.{Environment.NewLine}Program icon will appear on system tray.{ Environment.NewLine}{Environment.NewLine}Press print-screen key to use the program!", "First run", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                // TODO File exist, try to load it [can be made flag-based for both conditions to set a single flag and unify save settings data call]
                try
                {
                    // Populate settings data
                    this.settingsData = this.LoadSettingsData();
                }
                catch
                {
                    // There is an error when loading, recreate settings file
                    this.SaveSettingsData();
                }
            }

            // Process settings
            this.ProcessSettings();

            // Iterate image format menu items
            foreach (ToolStripMenuItem item in this.imageFormatToolStripMenuItem.DropDownItems)
            {
                // Check based on it being in current settings
                item.Checked = item.Text.Substring(1).ToLowerInvariant() == this.settingsData.SaveImageFormat;
            }
        }