コード例 #1
0
ファイル: HotKey.cs プロジェクト: pengyancai/cs-util
        /// <summary>
        /// Copy constructor.
        /// </summary>
        /// <param name="other"></param>
        public HotKey(HotKey other)
        {
            counter++;

            this.Action = other.Action;
            this.HotID = other.HotID;
            this.Code = other.Code;
            this.Modifier = other.Modifier;
        }
コード例 #2
0
ファイル: KeyManager.cs プロジェクト: pengyancai/cs-util
        //========================================================================================
        // Methods
        //========================================================================================
        /// <summary>
        /// Register a new hot key sequence, associating it with the specified action.
        /// </summary>
        /// <param name="code">The primary keyboard key-code identifier.</param>
        /// <param name="modifier">The secondary keyboard modifiers bit mask.</param>
        /// <param name="action">The well-known action to associated with the hot key.</param>
        public void RegisterHotKey(Keys code, KeyModifier modifier, HotKeyAction action)
        {
            HotKey key = new HotKey(action, code, modifier);
            bool ok = true;

            if (code != Keys.None)
            {
                try
                {
                    ok = KeyInterops.RegisterHotKey(window.Handle, key.HotID, (int)modifier, (int)code);
                }
                catch (Exception exc)
                {
                    Logger.WriteLine("RegisterHotKey", exc);
                }
            }

            if (ok)
            {
                keys.Add(key.Action, key);
            }
            else
            {
                MessageWindow.Show(
                    String.Format(Resx.HotKeyNotRegistered, key.Action, key.ToString()));

                key.Code = Keys.None;
                key.Modifier = KeyModifier.None;

                if (keys.ContainsKey(action))
                {
                    keys[action] = key;
                }
                else
                {
                    keys.Add(action, key);
                }
            }
        }
コード例 #3
0
        private void DoKeyPressed(HotKey key)
        {
            HotKey entry = editor.SelectedItem as HotKey;
            if (entry != null)
            {
                map.SetSequence(entry, key);
            }

            // resize the columns to fix any changes in content width
            GridView grid = editor.View as GridView;
            if (grid != null)
            {
                foreach (GridViewColumn column in grid.Columns)
                {
                    column.Width = column.ActualWidth;
                    column.Width = Double.NaN;
                }
            }
        }