This project is read-only.

InputControl not letting go of input?

Mar 22, 2011 at 9:41 AM

So, I'm building a simple Console interface, and I extended the InputControl to fire off an event when it detects enter being pressed.  However, I can't get InputControl to let go of the input once it's been selected.  I've tried setting InputControl.Enabled to false, which doesn't seem to work.  I can't set HasFocus to false since it's read only, and there is no method to force the control to let go of focus and let the rest of my input structure take control.  

Mar 22, 2011 at 9:43 AM

Also, since I think it will benefit the community, here is my ActivatedInputControl.  It's very simple and works exactly like buttons.  

 

  class ActivatedInputControl : InputControl
    {

        public event EventHandler Activated;


        /// <summary>
        /// Checks for newline, if so, activate
        /// </summary>
        /// <param name="character"></param>
        protected override void OnCharacterEntered(char character)
        {
            if (character == '\n' || character == '\r')
            {
                OnActivate();
                return;
            }

            base.OnCharacterEntered(character);
        }

        /// <summary>
        /// Checks if enter was pressed, if so, activates
        /// </summary>
        /// <param name="keyCode"></param>
        /// <returns></returns>
        protected override bool OnKeyPressed(Keys keyCode)
        {
            if (!HasFocus) return false;

            if (keyCode == Keys.Enter)
            {
                OnActivate();
                return true;
            }

            return base.OnKeyPressed(keyCode);
        }

        /// <summary>
        /// Call our delegate and clear text
        /// </summary>
        protected void OnActivate()
        {
            if (Activated != null)
            {
                Activated(this, EventArgs.Empty);
                Text = string.Empty;
                
            }
        }