09-07-2010 09:41 AM
I am trying to implement some additional behavior to numeric controls in a software that uses SI prefix representation. Mainly I want to prevent the end user to overwrite a prefix unconsciously while he is tabbing from control to control, double-clicking in the field or selecting digits with the mouse. In these 3 cases the prefix has to be excluded automatically from the selection, so the end user overwrites only the numeric digits, but keeps the prefix. The end user can delete or overwrite the prefix only when he explicitly sets the cursor next to the prefix or selects the prefix. An additional external control just for the prefix is not an option here.
Tabbing from control to control (with the Key Up event) and double-clicking in the field (with the Mouse Down event) are working fine, but I have a problem while selecting all digits with the mouse. It's only working when I select digits from the left to the right and don't leave the control (Mouse Up event) or when I select from the right to the left and leave the control to the left (Mouse Leave event). The case, when I select from to left to the right, leaving the control to the right is not working.
Has anybody an idea, how to solve this? What am I overlooking?
Could it be a problem of the text selection end property (NumText.SelEnd) in the numeric control? I have this suspicion, because I try also to prevent the cursor from getting to the very right position (right from the prefix) when increasing digits with the cursor keys, and found a case where this property seems not to work how I want. I'm checking the cursor position after every value change, and want to write the cursor on the left of the prefix, if the cursor get's to the right of the prefix. This is not working, when i increase e.g. 999¦k with the cursor key "up" between last numeric digit and prefix, the cursor should still be at the position between the last numeric digit and the prefix 1¦M, but it stays to my surprise at the right side of the prefix 1M¦. Any ideas?