473,407 Members | 2,598 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Character Subsitution

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.

--
Best Regards - OHM

O_H_M{at}BTInternet{dot}com

Nov 20 '05 #1
7 1237
"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.
--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #2
Hi,

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

Ken
-----------
"One Handed Man [ OHM# ]" <O_H_M{at}BTInternet{dot}com> wrote in message news:OD**************@TK2MSFTNGP12.phx.gbl...
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.

--
Best Regards - OHM

O_H_M{at}BTInternet{dot}com

Nov 20 '05 #3
* "One Handed Man [ OHM# ]" <O_H_M{at}BTInternet{dot}com> scripsit:
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).

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #4
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
Herfried K. Wagner [MVP] wrote:
* "One Handed Man [ OHM# ]" <O_H_M{at}BTInternet{dot}com> scripsit:
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).


--
Best Regards - OHM

O_H_M{at}BTInternet{dot}com
Nov 20 '05 #5
"One Handed Man [ OHM# ]" <O_H_M{at}BTInternet{dot}com> schrieb
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 ?


You can still write a textbox completely on your own. ;-) If you need a
caret:
http://msdn.microsoft.com/library/en...ces/carets.asp

;-)
--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #6
* "Armin Zingler" <az*******@freenet.de> scripsit:
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 ?


You can still write a textbox completely on your own. ;-) If you need a
caret:
http://msdn.microsoft.com/library/en...ces/carets.asp


ROTFL

A basic implementation in VB6 can be found here:

<http://www.vbthunder.com/default.asp?srcget=37>

SCNR

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #7
WTF ?
Herfried K. Wagner [MVP] wrote:
* "Armin Zingler" <az*******@freenet.de> scripsit:
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 ?
You can still write a textbox completely on your own. ;-) If you
need a caret:

http://msdn.microsoft.com/library/en...ces/carets.asp
ROTFL

A basic implementation in VB6 can be found here:

<http://www.vbthunder.com/default.asp?srcget=37>

SCNR


--
Best Regards - OHM

O_H_M{at}BTInternet{dot}com
Nov 20 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: teachtiro | last post by:
Hi, 'C' says \ is the escape character to be used when characters are to be interpreted in an uncommon sense, e.g. \t usage in printf(), but for printing % through printf(), i have read that %%...
15
by: wizardyhnr | last post by:
i want to try ANSI C99's unicode fuctions. so i write a test program. the function is simple, but i cannot compile it with dev c++ 4.9.9.2 under windows xp sp2, since the compiler always think that...
17
by: =?Utf-8?B?R2Vvcmdl?= | last post by:
Hello everyone, Wide character and multi-byte character are two popular encoding schemes on Windows. And wide character is using unicode encoding scheme. But each time I feel confused when...
3
KevinADC
by: KevinADC | last post by:
Purpose The purpose of this article is to discuss the difference between characters inside a character class and outside a character class and some special characters inside a character class....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.