I'm looking for some help how to add text in XNA? I'm doing a game where I want the player to enter his or her name in the beginning. Is ther a simple way to do this? Help is preciated! Thanks!


1 Answer 1


Had a post dedicated to this on my blog. I need to set my server back up :/

Anyways keyboard input in XNA is very poorly supported. Many including myself prefer to use a windows form event hook. This makes things very simple. Code below is very C#ish pseudocode off the top of my head so you may need to tweak it.

// Just draw this string
string text = "";

//Add an event for a character being added
InputSystem.CharEntered += delegate(Object o, CharacterEventArgs e) {
    if (Font.Characters.Contains(character)) {
        text += e.Character;
    } else if (e.Character == '\b' /* backspace */) {
        if (text.lenght > 0 ) { text = text.substring(0, text.lenght - 1); }

Unfortunately the above only works on the pc, though it sounds like that is your development environmental.

If you will need additional GUI controls it might be worth downloading a 3rd party library such as Neoforce, XNAGui (Mine), or Nuclex.

  • \$\begingroup\$ Thanks! Looks complicated, but will try it later! \$\endgroup\$
    – 3D-kreativ
    Commented Aug 26, 2012 at 7:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .