コード例 #1
0
        /// <summary>
        /// Dispose ClipboardManager and HotKeyRegister when the form is closed.
        /// </summary>
        protected override void OnClosed(EventArgs e)
        {
            Console.WriteLine("Closing.");
            if (copyHotKeyToRegister1 != null)
            {
                copyHotKeyToRegister1.Dispose();
                copyHotKeyToRegister1 = null;
            }

            if (pasteHotKeyToRegister1 != null)
            {
                pasteHotKeyToRegister1.Dispose();
                pasteHotKeyToRegister1 = null;
            }

            if (clipboardManager != null)
            {
                clipboardManager.Dispose();
                clipboardManager = null;
            }

            if (trayIcon != null)
            {
                trayIcon.Dispose();
                trayIcon = null;
            }

            base.OnClosed(e);
        }
コード例 #2
0
        private void btnPasteUnregister_Click(object sender, System.EventArgs e)
        {
            // Dispose the hotKeyToRegister.
            if (pasteHotKeyToRegister1 != null)
            {
                pasteHotKeyToRegister1.Dispose();
                pasteHotKeyToRegister1 = null;
            }

            // Dispose the hotKeyToRegister.
            if (pasteHotKeyToRegister2 != null)
            {
                pasteHotKeyToRegister2.Dispose();
                pasteHotKeyToRegister2 = null;
            }

            // Dispose the hotKeyToRegister.
            if (pasteHotKeyToRegister3 != null)
            {
                pasteHotKeyToRegister3.Dispose();
                pasteHotKeyToRegister3 = null;
            }

            // Update the UI.
            tbPasteHotKey.Enabled      = true;
            btnPasteRegister.Enabled   = true;
            btnPasteUnregister.Enabled = false;
        }
コード例 #3
0
        private void tbPasteHotKey_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
        {
            // The key event should not be sent to the underlying control.
            e.SuppressKeyPress = true;

            // Check whether the modifier keys are pressed.
            if (e.Modifiers != Keys.None)
            {
                Keys         key       = Keys.None;
                KeyModifiers modifiers = HotKeyRegister.GetModifiers(e.KeyData, out key);

                // If the pressed key is valid...
                if (key != Keys.None)
                {
                    this.pasteRegisterKey       = key;
                    this.pasteRegisterModifiers = modifiers;

                    // Display the pressed key in the textbox.
                    tbPasteHotKey.Text = string.Format("{0}+{1}", this.pasteRegisterModifiers, this.pasteRegisterKey);

                    // Enable the button.
                    btnPasteRegister.Enabled = true;
                }
            }
        }
コード例 #4
0
        private void btnPasteRegister_Click(object sender, System.EventArgs e)
        {
            try
            {
                // Register the hotkey.
                pasteHotKeyToRegister1 = new HotKeyRegister(this.Handle, pasteHotKeyRegisterId1, this.pasteRegisterModifiers, this.pasteRegisterKey);
                // Register the HotKeyPressed event.
                pasteHotKeyToRegister1.HotKeyPressed += new EventHandler <int>(PasteHotKeyPressed);

                // Register the hotkey.
                pasteHotKeyToRegister2 = new HotKeyRegister(this.Handle, pasteHotKeyRegisterId2, this.pasteRegisterModifiers, this.pasteRegisterKey + 1);
                // Register the HotKeyPressed event.
                pasteHotKeyToRegister2.HotKeyPressed += new EventHandler <int>(PasteHotKeyPressed);

                // Register the hotkey.
                pasteHotKeyToRegister3 = new HotKeyRegister(this.Handle, pasteHotKeyRegisterId3, this.pasteRegisterModifiers, this.pasteRegisterKey + 2);
                // Register the HotKeyPressed event.
                pasteHotKeyToRegister3.HotKeyPressed += new EventHandler <int>(PasteHotKeyPressed);

                // Update the UI.
                btnPasteRegister.Enabled   = false;
                tbPasteHotKey.Enabled      = false;
                btnPasteUnregister.Enabled = true;
            }
            catch (ArgumentException argumentException)
            {
                MessageBox.Show(argumentException.Message);
            }
            catch (ApplicationException applicationException)
            {
                MessageBox.Show(applicationException.Message);
            }
        }
コード例 #5
0
        /// <summary>
        /// Handle the Click event of btnUnregister.
        /// </summary>
        private void btnCopyUnregister_Click(object sender, EventArgs e)
        {
            // Dispose the hotKeyToRegister.
            if (copyHotKeyToRegister1 != null)
            {
                copyHotKeyToRegister1.Dispose();
                copyHotKeyToRegister1 = null;
            }

            // Dispose the hotKeyToRegister.
            if (copyHotKeyToRegister2 != null)
            {
                copyHotKeyToRegister2.Dispose();
                copyHotKeyToRegister2 = null;
            }

            // Dispose the hotKeyToRegister.
            if (copyHotKeyToRegister3 != null)
            {
                copyHotKeyToRegister3.Dispose();
                copyHotKeyToRegister3 = null;
            }

            // Update the UI.
            tbCopyHotKey.Enabled      = true;
            btnCopyRegister.Enabled   = true;
            btnCopyUnregister.Enabled = false;
        }