What am I doing wrong with IMessageFilter?

V

vbMark

Here is my class:

Public Class clsTextBox

Inherits TextBox
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

Public Function PreFilterMessage(ByRef m As _
Microsoft.WindowsCE.Forms.Message) As Boolean _
Implements OpenNETCF.Windows.Forms.IMessageFilter.PreFilterMessage
Try
Select Case m.Msg 'Break point here!
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 Class

Here is the important stuff of my Main Form:
..
..
Private m_oTextBox() As clsTextBox
..
..
Private Sub Form_KeyDown(ByVal e As System.Windows.Forms.KeyEventArgs, _
ByVal lparam As Int32)
MsgBox("yo")
End Sub
..
..
m_oTextBox(x) = New clsTextBox(AddressOf Form_KeyDown)
..
..
ApplicationEx.AddMessageFilter(m_oTextBox(x))
..
etc.

The key down events are just not intercepted.

Putting a breakpoint in PreFilterMessage shows that code never goes
there.

I get no errors and everything works fine but not the intercept.

What am I missing or doing wrong?

Thanks!
 
S

Sergey Bogdanov

In addition to Chris' post make sure that you have added IMessageFilter
to ApplicationEx filter collection:

ApplicationEx.AddMessageFilter(clsTextBoxInstance);


Best regards,
Sergey Bogdanov
http://www.sergeybogdanov.com
 
V

vbMark

I already tried that. I did "Current Project" and "Entire Solution" and
still not found.

Does it matter that I'm using Visual Basic .NET?
 

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