On Mon, 11 Jun 2007 16:02:02 -0700, Ray Mitchell
<Ra*****************@MeanOldTeacher.comwrote:
[...]
Although I may be mistaken, it appears that during the bacspace
algorithm the
caret momentarily jumps to the beginning of the string containing the
text
for the entire control, then back to where it belongs.
It does that, and more.
You are replacing the entire text of the control with a whole new group of
text. When this happens, the control has no way to know that the text is
only different by a single character. It acts as though it would when you
replace the text of a control with any new text: it resets the selection
and redraws the entire control. The selection winds up back at the end
because you explicitly put it there.
For what it's worth, the flashing is almost certainly mostly due to
replacing the text, and not to the selection change.
Commercial
applications I've seen don't have this problem so I'm sure I'm doing
something wrong. Any ideas?
Well, a couple of thoughts:
1) I'm not really clear on why you need a "backspace algorithm". The
text box control handles the backspace key just fine.
2) If what you are doing is mapping some other kind of input to the
text box in a way that should emulate the user pushing the backspace even
when they are not, one thing you can do is send the appropriate keys
directly. There are a variety of ways you can try to do this, none of
them great IMHO. The most popular is probably the SendKeys class, but as
near as I can tell, there is no way to guarantee that your own application
will actually get the keys, and it would require that the text box control
has the current focus (which may or may not be true in your case).
If I really wanted to approach it this way, I would create a derived class
from the text box class, and then provide specific methods to simulate the
input you want, creating a Message instance that emulates the keyboard
input you want to emulate, and calling the WndProc method for the control,
passing that Message to it. You'll probably have to simulate the
WM_KEYDOWN and WM_KEYUP messages at a minimum; I'm not sure what else
you'd have to do, but it could be a little tricky to get it just right (or
it might not...like I said, I'm not sure :) )
3) Probably the best way to handle it would be to do it the way that
"commercial applications" most likely do it (I can't speak for any
specific one, since you didn't mention which ones you're talking about).
That is, they don't use the built-in edit controls, and they don't wind up
having to redraw the entire control just because one character changed.
It wouldn't be hard to create your own textbox control, and if you do so
you can provide right in the control whatever mechanism you want for
dealing with backspaces and other types of input not coming directly from
the user's keyboard. You would also be able to in that case make sure
that only the part of the control that actually needed redrawing when some
text was changed was actually redrawn.
Pete