Search code examples
c#timertextboxevent-handling

Pausing Textbox Value that is constantly being read until "Enter" is pressed


I have a textbox whose text input is constantly being read via a timer that runs every 100ms. I want to find a way (perhaps creating an event) that allows me to keep reading the previously inputted data until I have hit "Enter" on my keyboard or used my mouse in some way.

The current behavior is whenever I try to input a new number into this textbox, the value I put in gets read in "chunks" if it's a larger value. What I mean is that if I input any value higher than two digits eg. "10" and beyond, the value gets read as "1" then "10." And it gets worse for values that are in the hundreds

[Ex] 350 gets read as first "3" then "35" then finally "350."

This is of course because of the timer event happening so quickly, but it needs to be 100ms for the overall system.

I'm wondering if someone has an elegant way of allowing me to enter a number that is greater than 10 that will be read in as the full value instead of being broken up. I think this will have to be a "text_changed" event or something similar but I'm having difficultly implementing this


Solution

  • I Found a solution.

    I'm simply hiding the initial textbox and then showing a new textbox in the exact same place that can take user input. I created an event that if you double click in the original textbox, it hides and another one is shown in it's place without the user even knowing. This allows the timer to keep reading from the original textbox while allowing the user to manually input a new value. I created a second event that waits for "Enter" to be pressed, and then assigns the new value to the original textbox, and volia!