• Advertisement
Sign in to follow this  

TextBox implementation

This topic is 1584 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello, for some time making my game engine. Just as hobby to understand how games works smile.png

 

Now trying to make TextBox implementation, but really can't think any good implementation. While using XNA, I made property  "WriteWord": 

        public string WriteWord
        {
            get
            {
                string letter = string.Empty;
                Keys key = Key;
                if (key >= Keys.A && key <= Keys.Z && _writeWord.Length < 9)
                    letter = key.ToString();
                else if (key == Keys.Back && _writeWord.Length != 0)
                    _writeWord = _writeWord.Remove(_writeWord.Length - 1);
                _writeWord += letter;
                return _writeWord;
            }
        }

        public Keys Key
        {
            get
            {
                return
                    _pState.GetPressedKeys()
                           .FirstOrDefault(key => _pState.IsKeyDown(key)
						   && Keyboard.GetState().IsKeyUp(key));
            }
        }

and simple WriteWord value was set to TextBox value, and simply gets visual effect of typing and deleting. Maybe hard to understand how it works, and maybe not whole code where is, but it worked for my, having only one textBox (don't tested on more). But this implementation is not best... I think it's most worse as there can be smile.png

 

Now I using directInput and on keyDown I get codes like DIK_RIGHTARROW, DIK_1, DIK_S and so on... And for graphics - DirectX 9.

 

So, maybe somebody show how better implement TextBox? smile.png

Share this post


Link to post
Share on other sites
Advertisement

For various reasons, Microsoft decided to deprecate DirectInput several versions ago. The good news is that key translation is a whole lot simpler if you use the Windows message loop.

 

You might be interested in a relevant question on Stack Overflow.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement