Re: Some questions about INTRACTIVECHANGE Event.
- From: "Dan Freeman" <spam@xxxxxxxxxxxxx>
- Date: Wed, 31 Jan 2007 20:26:26 -0800
Let me preface this by saying I usually don't comment on any attempt to
attain precision pixel widths of strings. It's truly a sinkhole of time.
I've known many people who are way smarter than me who worked very hard on
the issue, and the best they can come up with is an approximation. Every one
of them said they'd never do it again.
That said, you've answered your own question when you said the value
evaluated properly in Valid but not in keypress. The control's Value
property doesn't get written to the control's Controlsource until focus
leaves the control. In keypress, focus hasn't attempted to leave the
control. In Valid, the Value has been written to Controlsource.
I *think* (but this is distant memory) that This.TextWidth() evaluates the
controlsource. So before you evaluate Textwidth(), cause the control's Value
to be written to the controlsource by using This.Setfocus().
I don't see where you're initializing the value stored in OWNER, nor where
it's being written as you're running through this process. You *might* be
facing a simple scoping issue. We see enough of those around here. But my
money is on figuring out which value you're really evaluating in
Textwidth().
Dan
"Jud" <judsonrp@xxxxxxxxxxx> wrote in message
news:1170300217.897937.23980@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Hi,
This is VFP6 SP5.
My intent was to make a TextBox which would, while I was typing, let
me know when I had typed too many characters to fit within a fixed
number of pixels, and remove the last character I had just typed.
I started with "_234567890_234567890 " in the TextBox
OWNER_ TEXT.
I then added three "x"s to get "_234567890_234567890xxx "
which calls the following code 3 times.
*** This is OWNER_TEXT.INTERACTIVECHANGE:
acti screen
? [||| in -- "] + owner + ["]
IF THIS.TEXTWIDTH( ALLTRIM(OWNER) ) > OWNERMAX
* OVER the Maximum.
?? CHR(7) + CHR(7)
THIS.FORECOLOR = 255 && RED
INKEY(0.3, "HM")
OWNER = ALLTRIM(OWNER)
DO WHILE THIS.TEXTWIDTH( OWNER ) > OWNERMAX
OWNER = LEFT(OWNER, LEN(OWNER) - 1)
ENDDO while over.
OWNER = PADR(OWNER, 50)
THIS.FORECOLOR = 0 && BLACK
ENDIF over.
? [||| out- "] + owner + ["]
------------------- end of code.
As I typed, this produced:
||| in -- "_234567890_234567890 "
||| out- "_234567890_234567890 "
||| in -- "_234567890_234567890 "
||| out- "_234567890_234567890 "
||| in -- "_234567890_234567890 "
||| out- "_234567890_234567890 "
This Event does see the changes and reacts, but the value of OWNER
passed to it does not contain them, even though OWNER has too many
characters. And therefore, the IF...ENDIF statement is never true.
Until Tab or Enter is pressed and focus moves to another control, then
code in the OWNER_TEXT.VALID event does see the added "x"s and removes
them, using similar code.
My Help system says the following:
--------
InteractiveChange Event
Occurs when the user changes the value of a control using the keyboard
or the mouse.
Remarks
This event occurs each time the object's value changes interactively.
For example, as a user types in a text box, the InteractiveChange
event is triggered after each keystroke.
--------
KeyPress Event
Occurs when the user presses and releases a key.
Remarks
A KeyPress event is useful for intercepting keystrokes entered in a
control. It enables you to immediately test keystrokes for validity or
to format characters as they are typed. Use the KeyPreview property to
create global keyboard-handling routines.
-------- end of Help.
Neither the InteractiveChange or KeyPress Event seem to see anything
but the variable as it existed when focus was brought to the TextBox.
And have no access to the actual contents, visible in the TextBox as
you type.
Am I missing something? Is it possible to evaluate the actual
contents between key presses as I type, and do something about them?
Any help would be greatly appreciated. Thanks in advance.
Jud
.
- Follow-Ups:
- References:
- Prev by Date: Re: Some questions about INTRACTIVECHANGE Event.
- Next by Date: Re: Some questions about INTRACTIVECHANGE Event.
- Previous by thread: Re: Some questions about INTRACTIVECHANGE Event.
- Next by thread: Re: Some questions about INTRACTIVECHANGE Event.
- Index(es):
Relevant Pages
|