Character Subsitution

  • Thread starter Thread starter One Handed Man [ OHM# ]
  • Start date Start date
O

One Handed Man [ OHM# ]

OK, here is a mildy interesting one. What is the cleanest way to do the following.


Every time a keyPress event occurs, I wan to check for the quote ( " ) and subsitute it for the apostrophe ( ' ). Detecting this is easy, but what is the cleanest way to subsitute that character in the current cursor position in the textbox. Its a pity that you cannot alter the KeyValue but all those properties are readonly.

The reason I'm asking this is because I have to leave for a couple of hourse and just wondered if I might have it solved by the time I return.
 
"One Handed Man [ OHM# ]" <O_H_M{at}BTInternet{dot}com> schrieb
OK, here is a mildy interesting one. What is the cleanest way to do the
following.


Every time a keyPress event occurs, I wan to check for the quote ( " ) and
subsitute it for the apostrophe ( ' ). Detecting this is easy, but what is
the cleanest way to subsitute that character in the current cursor position
in the textbox. Its a pity that you cannot alter the KeyValue but all those
properties are readonly.

The reason I'm asking this is because I have to leave for a couple of hourse
and just wondered if I might have it solved by the time I return.


======

I prefer not interferring in the key events - which could be bypassed using
the clipboard anyway - but instead I'd use the validating event.

Or (untested): Handle the TextChanged event. Store the caret location (or
selection) before replacing the quote char and set the caret
location/selection afterwards back to the previous values. Might result in
flickering...well, untested.
 
Hi,

My thought was to override the processkeypressargs event. Hope that helps.
http://msdn.microsoft.com/library/d...formscontrolclassprocesskeyeventargstopic.asp

Ken
-----------
"One Handed Man [ OHM# ]" <O_H_M{at}BTInternet{dot}com> wrote in message OK, here is a mildy interesting one. What is the cleanest way to do the following.


Every time a keyPress event occurs, I wan to check for the quote ( " ) and subsitute it for the apostrophe ( ' ). Detecting this is easy, but what is the cleanest way to subsitute that character in the current cursor position in the textbox. Its a pity that you cannot alter the KeyValue but all those properties are readonly.

The reason I'm asking this is because I have to leave for a couple of hourse and just wondered if I might have it solved by the time I return.
 
* "One Handed Man said:
OK, here is a mildy interesting one. What is the cleanest way to do the following.

Remember: You are asking for the cleanest way.
Every time a keyPress event occurs, I wan to check for the quote ( " ) and subsitute it for the apostrophe ( '
). Detecting this is easy, but what is the cleanest way to subsitute that character in the current cursor
position in the textbox. Its a pity that you cannot alter the KeyValue but all those properties are readonly.

I would not change the characters at all. I would do the formatting in
the control's 'Validating' event. Suppressing keys and changing key
codes won't be done if the user pastes some text from the clipboard. I
always hated applications which did restict me in formatting the text I
wanted to enter while working in the textbox. The preferred way is IMHO
to do the formatting in the validation (when the control looses focus,
for example).
 
Thanks to all for answering my post. I think I will stick with the
Validating event as suggested by Armin and Herfreid. However, I would like
to see some changes which would allow the transposition of character codes.
Maybe in another version ?


Regards - OHM
 
Back
Top