コード例 #1
0
        protected void Key_KeyPress(object o, KeyPressEventArgs args)
        {
            Entry txtKey = (Entry)o;

            if (!IsSelectionValid(GetSelectedRow()))
            {
                return;
            }

            Key          key;
            ModifierType mod;

            KeyShortcuts.MapRawKeys(args.Event, out key, out mod);
            AccelKey newAccelKey = new AccelKey(key, mod, AccelFlags.Visible);

            if (KeyShortcuts.CombinationValid(key, mod))
            {
                enteredAccelKey = newAccelKey;
                txtKey.Text     = KeyShortcuts.KeyToString(enteredAccelKey);
            }
            switch (args.Event.Key)
            {
            case Key.BackSpace:
                if (KeyShortcuts.GetAllowedModifier(args.Event.State) == ModifierType.None)
                {
                    enteredAccelKey = new AccelKey(Key.VoidSymbol, ModifierType.None, AccelFlags.Visible);
                    txtKey.Text     = string.Empty;
                }
                break;

            case Key.KP_Enter:
            case Key.Return:
            case Key.Escape:
                return;
            }
            args.RetVal = true;
        }