KeyPreview?

  • Thread starter Thread starter Kim D
  • Start date Start date
K

Kim D

Help please!!!!

How do I keypreview with compactframework? There is no form property for this. I need to capture barcode scanner input. .

Kim
 
There are many ways to overcome this. The simplest solution is to
implemented the KeyPressed event for all the controls that can be focussed
on your form.
Joseph Gia
Help please!!!!
How do I keypreview with compactframework? There is no form property for
this. I need to capture barcode scanner input. .
Kim
 
Use an IMessageFilter implementation.

www.opennetcf.org/sdf

-Chris


Help please!!!!

How do I keypreview with compactframework? There is no form property for this. I need to capture barcode scanner input. .

Kim
 
Sample implementation of IMessageFilter
------------------------------------------
#Region "KeyDown MessageFilter"

Class KeyDownMeaagseFilter
Implements OpenNETCF.Windows.Forms.IMessageFilter

Delegate Sub MyKeyDownDelegate(ByVal e As KeyEventArgs, ByVal lparam
As Integer)

Private myfunc As MyKeyDownDelegate

Public Sub New(ByVal DelegateFunction As MyKeyDownDelegate)
myfunc = DelegateFunction
End Sub

#Region "Pre Message Filter Function "
Public Function PreFilterMessage(ByRef m As
Microsoft.WindowsCE.Forms.Message) As Boolean Implements
OpenNETCF.Windows.Forms.IMessageFilter.PreFilterMessage

Try
Select Case m.Msg
Case Window.Messages.WM_KEYDOWN
myfunc.Invoke(New KeyEventArgs(m.WParam.ToInt32),
m.LParam.ToInt32)
End Select

Catch ex As Exception

MsgBox(ex.ToString)

End Try

End Function
#End Region
------------------------------------------------------------------
Window Message Constatnts
#Region "Window Message constants "

Public Class Window

Friend Enum Messages As Integer
' Fields
WM_ACTIVATE = 6
WM_ACTIVATEAPP = 28
WM_CANCELMODE = 31
WM_CHAR = 258
WM_CHILDACTIVATE = 34
WM_CLOSE = 16
WM_COMMAND = 273
WM_CREATE = 1
WM_DEADCHAR = 259
WM_DESTROY = 2
WM_DEVMODECHANGE = 27
WM_ENABLE = 10
WM_ERASEBKGND = 20
WM_FONTCHANGE = 29
WM_GETMINMAXINFO = 36
WM_GETTEXT = 13
WM_GETTEXTLENGTH = 14

WM_KEYDOWN = 256
WM_KEYFIRST = 256
WM_KEYUP = 257

WM_KILLFOCUS = 8

WM_LBUTTONDOWN = 513
WM_LBUTTONUP = 514
WM_MOUSEACTIVATE = 33
WM_MOUSEMOVE = 512

WM_MOVE = 3
WM_NOTIFY = 78
WM_NULL = 0
WM_PAINT = 15
WM_QUEUESYNC = 35
WM_QUIT = 18
WM_SELECT = 5022

WM_SETCURSOR = 32
WM_SETFOCUS = 7
WM_SETREDRAW = 11
WM_SETTEXT = 12
WM_SETTINGCHANGE = 26
WM_SHOWWINDOW = 24
WM_SIZE = 5
WM_SYSCHAR = 262
WM_SYSCOLORCHANGE = 21
WM_SYSDEADCHAR = 263
WM_SYSKEYDOWN = 260
WM_SYSKEYUP = 261
WM_TIMECHANGE = 30
WM_WININICHANGE = 26
End Enum
End Class
#End Region
----------------------------------------------------------------------
Create an object of KeyDownMessageFilter on form
----
Private MyKeyDownFilterf As New KeyDownMeaagseFilter(AddressOf
TempForm_KeyDown)
----
Add this line to the constructor routine

ApplicationEx.AddMessageFilter(MyKeyDownFilterf)
-----------------

Private Sub TempForm_KeyDown(ByVal e As System.Windows.Forms.KeyEventArgs,
ByVal lparam As Int32)
'Add code for handling messages.
End Sub
 
How will it work on Tabbed dialog? As I checked it does not work. Should I
extend ApplicationEx?
Jacek
 
Back
Top