locked
How can i force a textbox to overwrite the text, like the keyboard insert key is turned off

    Question

  • I have a textbox with maxlength=2

    How can i fore the textbox to overwrite the text in the textbox like the keyboard 'insert key' is turned off?

    Friday, March 21, 2014 11:26 AM

All replies

  • You can't. What you can do is clear the text on focus.  I'm not sure what you're trying to accomplish here.

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Friday, March 21, 2014 2:48 PM
    Moderator
  • I'm working on a stopwatch. I have 3 textboxes with a maxlength of 2, and when a textbox gets focus i want to overwrite the numer in the textbox, but not only 1 character at a time, starting with the left character.

    So if the textbox has a value of '12' then i what i want is if the textbox gets focus, and i start typing '3' that the '1' will be overwritten so the new value is '32'. That's the same behaviour as that the 'insert key' is off.

    I found a .net example with the following methode:

    SendKeys.Send({INSERT})

    This won't work with xaml, so i lokking for replacement code...

    Friday, March 21, 2014 4:51 PM
  • Use separate TextBoxes for each digit, select the text when focused, and advance the focus to the next box when the text changes.

    Also consider skin controls for the digits.

    Friday, March 21, 2014 5:39 PM
    Owner
  • That's one option, but i don't want the complete text selected, but in the textbox one digit at a time. I just want to overwite one character at a time, just like the keyboard 'insert key' set to off...
    Saturday, March 22, 2014 12:09 AM