Exemplo n.º 1
0
        /// <summary>
        /// Called, if a character on the keyboard has been pressed.
        /// Passes this event to all elements within the layout.
        /// </summary>
        /// <param name="e">An object containing information about the event.</param>
        public override void CharPressed(KeyPressEventArgs e)
        {
            if (!visible)
            {
                return;
            }

            base.CharPressed(e);
            if (handled && text.Length < maxLength)
            {
                SFXPlayer.Play(Sound.Click1 + random.Next(0, 4));
                text += e.KeyChar;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Called if a key has been pressed.
        /// Passes this event to all elements within the layout.
        /// </summary>
        /// <param name="e">An object containing information about the event.</param>
        public override void KeyPressed(KeyEventArgs e)
        {
            if (!visible)
            {
                return;
            }
            base.KeyPressed(e);

            handled = true;
            switch (e.KeyCode)
            {
            // When the user is pressing backspace, the last character is deleted.
            // If the users is simultaneoulsy pressing control, the entire string is deleted.
            case Keys.Back:
                handled = false;
                if (text.Length > 0)
                {
                    text = text.Remove(text.Length - 1);
                    SFXPlayer.Play(Sound.Click1 + random.Next(0, 4));
                }
                if (e.Control)
                {
                    text = "";
                }
                break;

            // Ignore '\r' and '\n' and Escape
            case Keys.Enter:
            case Keys.Escape:
                handled = false;
                break;
            }

            // If the delimiter key is pressed, the OnDelimiterEntered Event is beeing invoked
            if (e.KeyCode == delimiter)
            {
                SFXPlayer.Play(Sound.Menu_Confirm);
                if (OnDelimiterEntered != null)
                {
                    OnDelimiterEntered.Invoke(this, new StringEventArgs(text));
                }
            }
        }