Z
Zief
Hi,
I am trying to figure out how to do a few things with key events in my
own class extending the TextBox.
I would like to change a ',' character into a '.' character in the
OnKeyPressed event. The KeyChar value is read-only though. I have
searched and found a post where it says to use PostMessage to try and
post a '.' character back to the control, and then use e.Handled = true
to cancel the ',' character, but this does not seem to work. Does
anyone have any suggestions?
I would also like to cancel certain key presses, but this cannot be
determined in the OnKeyPressed event, as you cannot analyse the text
with the key that has been pressed (in the particular position it is
going to go into the text) at this point. The Text property only holds
the previous text in this event. I can determine whether or not to
cancel the key in the TextChanged event, but if I then revert this to
the previous text, the cursor position reverts to the beginning of the
textbox from whatever position it was previously in.
Again after a search, I thought I would be able to use GetCaretPos
before the change to save the cursor position, and the SetCaretPos
after the change to return it to the correct place. This also seems to
have no effect, so I am looking for suggestions here as well.
Thanks in advance of help,
Zief
I am trying to figure out how to do a few things with key events in my
own class extending the TextBox.
I would like to change a ',' character into a '.' character in the
OnKeyPressed event. The KeyChar value is read-only though. I have
searched and found a post where it says to use PostMessage to try and
post a '.' character back to the control, and then use e.Handled = true
to cancel the ',' character, but this does not seem to work. Does
anyone have any suggestions?
I would also like to cancel certain key presses, but this cannot be
determined in the OnKeyPressed event, as you cannot analyse the text
with the key that has been pressed (in the particular position it is
going to go into the text) at this point. The Text property only holds
the previous text in this event. I can determine whether or not to
cancel the key in the TextChanged event, but if I then revert this to
the previous text, the cursor position reverts to the beginning of the
textbox from whatever position it was previously in.
Again after a search, I thought I would be able to use GetCaretPos
before the change to save the cursor position, and the SetCaretPos
after the change to return it to the correct place. This also seems to
have no effect, so I am looking for suggestions here as well.
Thanks in advance of help,
Zief