KeyPreview in CF form?

Z

Zanna

Hi, again.

In VisualBasic I had the Form.KeyPreview property that let the form
intercept all key message before the focused control.

It is possible to do it with the CF?
I need to handle the input from a socket-barcode-scanner with no matter what
is the focused control.

Any way to do it?
 
G

Ginny Caughey [MVP]

Zanna,

You can use the MessageWindow class to trap ordinary Windows messages which
would include key presses, but is that what the scanner will be sending you?
 
Z

Zanna

Ginny Caughey said:
You can use the MessageWindow class to trap ordinary Windows messages which
would include key presses, but is that what the scanner will be sending
you?

Yes the scanner is a "keyboard-emulation".

I thinked also to do a loop for assgnigning to each control the
Form1_KeyPress event, but I don't know if it is possible in vb.net on CF.

I never used the MessageWindow class, and I cannot find it in the SDK.
Can you be so kind to post a couple of code-lines?

Thank you
 
M

Manni

I think the message window will not get those "Keyboard messages", since
your form has the focus
and keys are only sent to the window with the focus!
Otherwise your "Notes application" running in the background would get those
messages from your app!

Manfred
 
M

Manni

Most of those scanners are available to stop the keyboard emulation.
(Emulation is mostofall done by a litte "driver").

You can then alos read the scanner input via a comport!
We do this with a bluetooth and a socket CF-Card scanner!

Works better than the keyboard thing, because our users must not take care
where (tab-pages) on the form they are - when a scanner result comes - we
change the
view and place the code in the desired fields.

HTH

Manfred
 
S

Steven Licciardi

Yes you can do a loop assigning the KeyPress event, somthing along the following lines should do it:

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Dim c As Control

For Each c In Me.Controls

AddHandler c.KeyPress, AddressOf controlsKeyPress

Next

End Sub

Private Sub controlsKeyPress(ByVal sender As Object, ByVal e As KeyPressEventArgs)

If TypeOf (sender) Is TextBox Then

MessageBox.Show(CType(sender, TextBox).Text)

End If

End Sub



Steven.
 
Z

Zanna

Yes you can do a loop assigning the KeyPress event, somthing along the following lines should do it:



I tryed to do a generic sub to do this:


Public Sub SetKeyPreview(ByVal AddressOfKeyPressSub As [Delegate])

Dim c As Control

For Each c In Me.Controls

Try

AddHandler c.KeyPress, AddressOfKeyPressSub

Catch ex As Exception

' this control does not have a KeyPress event

End Try

Next

End Sub

Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

SetKeyPreview(AddressOf controlsKeyPress)

End Sub


But this give me an error I cannot understand:

(I translate, so it can be inaccurate)

SetKeyPreview(AddressOf controlsKeyPress) says "The expression AddressOf cannot be converted into a system.Delegate because a System.Delegate is not a delegate type.

There is a way to do what i want to?

Thank you
 

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