03-01-2011 09:35 AM
Want to know what's being deleted before commit.
03-01-2011 10:00 AM
You could check for a keypress event and read back the text every time a key is pressed (I assume you're talking about a string control) This way you could compare the previous with the new string...
03-01-2011 10:09 AM
Because it's before user commit, so when read back, I always get the same thing - the old value, no matter string or numeric control.
The purpose is to catch the event when user delete a "."
Thanks for reply.
03-01-2011 10:22 AM
-> don't use the commit event: in your EVENT_KEYPRESS case, check for 'Enter' to perform the action of your COMMIT case; there is a nice sample called multikey that visualizes key entries such as DELETE or ENTER
hth, Wolfgang
03-01-2011 11:16 AM
The problem isn't catch the DELETE keypress event, but in that event, what will be deleted.
03-01-2011 11:38 AM
well, my idea was to monitor the keypress event using GetKeyPressEventCharacter; if the keypress event is due to a regular character or a number, add the character to your string and save it; this way you will assemble your text or number character by character; if a DELETE is entered, look up the saved string; you also need to keep track of the cursor position; if a left arrow is entered, the position is reduced by one etc; if you enter a regular character, the position is increased by one... once a DELETE is recognized, you can get the deleted character from the tracked cursor position and the saved string
03-01-2011 12:20 PM
Thought about all this.
The problem is tracking cursor position. It's not blank to start with. It's hard to tell the cursor position in left click event.
Thank you so much for reply.
03-01-2011 01:11 PM - edited 03-01-2011 01:12 PM
When a key is pressed you get an EVENT_KEYPRESS and then an EVENT_VAL_CHANGED (assuming the keypress was not swallowed). Just watch for the delete key in the keypress event, save the text of the control pre-deletion, then set a flag letting your program know that the next EVENT_VAL_CHANGED is coming immediately after a delete. Then you can get the post-deletion string and compare the two.
03-01-2011 02:18 PM
That only apply to a string control. What if it's a numeric control?
Thanks for reply.
03-01-2011 02:41 PM
I can't think of anyway this could be done inside a numeric control because as you pointed out there's no EVENT_VAL_CHANGED generated on keypress (until the value is committed). There's also the issue that GetCtrlVal would return value 2.0 whether the text in the control when it was commited was "2" or "2.0000000" so you couldn't tell necessarily if the decimal had been deleted by the user. I guess I'm not entirely sure I understand why you need this functionality in a numeric control. Knowing that might give some an alternatives for you.
Since it can't be done in a numeric control, if you absolutely require this ability then you'd have to "fake" a numeric control using a string control. You could check the EVENT_KEYPRESS and have it swallow all characters other than 0-9, '.', '-', Enter, Delete and Backspace. You can always transform the text in this box to a float using the atof() function. You could even place the string control directly over a numeric control leaving only the Inc/Dec arrows visible. When a user clicked on an arrow you'd just need to get the value of the string, increment or decrement based on the numeric's increment value and then store the result of sprintf(buf, "%f", numericVal); back into the string. This is obviously pretty complex and there might be a few issues I'm forgetting but it could be done if you absolutely had to.