LostFocus Issue

A

Aaron

I'm using VB.NET and I can't seem to get my PPC app to behave the way
I want to. Simple problem here, but annoying, and I don't know if it
can be fixed but here goes...I have two text fields on a form as well
as 12 buttons that make up a numeric keypad I created. If the user is
in the first text field the keypad will be hidden, if the user puts
the cursor in field two, then the keypad is shown via the GotFocus
event, and when they place the cursor in the first field, keypad is
hidden. Of course this means that when they tap on a keypad button,
focus is lost from text field two and the keypad disappears without
firing it's event.

If I declare a global for the form and assign it when the click on a
keypad button and then in the LostFocus, check that variable before
hiding controls...it doesn't work. So it seems like my variable never
gets set since the LostFocus event is fired before a keypad's button's
OnClick event. Does anyone know of another method of doing this, or
what I can do differently to make this work as I want it to.

Thanks
 
P

Paul G. Tobey [eMVP]

It seems like what you really want is to change the display of the keypad
only when an EDIT control is *getting* focus, not when it's losing it. When
the one that needs the keypad receives focus, turn the keypad on. When the
control which does not gets focus, turn it off. That way, even if the focus
is lost to a keypad button, the keypad doesn't disappear until the right
time. Or you could just write a real SIP and you wouldn't have to worry
about it (but that has to be in C++, of course).

Paul T.
 
A

Aaron

Thanks Paul, that was simple enough and made sense. My question now
is how do I allow the user to backspace and delete the last charater
of a text field through code. There is a backspace key on my keypad
and when they press it, it just gives an ASCII box-like
character...here's what I did that obviously doesn't work:

Private Sub btnBkSp_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles btnBkSp.Click
txtWeight.Text = txtWeight.Text & Chr(8)
End Sub

Any suggestions?
 
P

Paul G. Tobey [eMVP]

Send a backspace? You can do it with keybd_event()... You wouldn't really
expecting adding a character to the text to remove a character, right?!

Paul T.
 
A

Aaron

Yes, actually I was, since there exists an ASCII character for a
backspace, I assumed I could use that (as I have in other scripting
languages) to delete the last character in my text field.

How can I use the keybd_event() if I'm not using the SIP?
 
A

Aaron

No, that'll work...I'm just new to .NET and VB so sometimes I will
miss the obvious. Thanks.
 
A

Aaron

When I press on one of my keypad buttons, the cursor is not visible
anymore in the text field cause it has lost focus. How do I put the
cursor at the end of the text in that particular text field?
 
P

Paul G. Tobey [eMVP]

You'd set the selection to move the cursor around within the text box and
call Focus() for it to set the focus there...

Note that Chris' previous post about 'backspace' only works if the selection
is at the end of the edit field. keybd_event (which you can find a managed
wrapper for in OpenNETCF), allows you to send a key just as though the user
tapped that key on a real keyboard connected to the device or tapped the SIP
key. The key goes through the whole input system, allowing the EDIT control
on which the TextBox class in .NET CF is based a chance to say, "Ah, a
backspace key. Move back one character, delete the character, handle the
case where there are already no characters in the EDIT field, and the case
where the contents should now scroll, etc." It's a more general solution, I
think...

Paul T.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top