Equivalent of PreTranslateMessage in C#

V

Vibhesh

Hello,

I have designed a form in C#. There are several controls
on the form. I want to trap all the events at the form
level before they are passed on to the controls.

For eg : Suppose there are two buttons on the form. At any
moment one of the two buttons will be focused. When I
press any key I want to perform some default processing at
the Form level before the events are caught by the Buttons.

I want something simillar to what PreTranslateMessage does
for CWnd in MFC.

Thanks.
 
N

Nicholas Paldino [.NET/C# MVP]

Vibhesh,

You have two options. The first is to override the PreProcessMessage
method on the Form that is hosting the controls. The second is to implement
the IMessageFilter interface and register it with the static
AddMessageFilter method on the Application class. If you do the latter,
then the implementation will be called before the messages are dispatched to
the form (the applications message loop will pass to registered message
filters first).

Hope this helps.
 
V

Vibhesh

Hello Nicholas,
Thanks for the reply.

Your first suggestion of overriding PreProcessMessage is
not working. Since at any moment the focus will be on any
one of the controls on the form, the key press event does
not passes to the PreProcessMessage or WinProc overriden
function of the Form.

Your second suggestion of IMessageFilter interface also
will not work in my solution.
I am calling the C# forms from my old C++ code and thus I
do not use Application class.

So do you have any other work-around for this problem.
Regards.



-----Original Message-----
Vibhesh,

You have two options. The first is to override the PreProcessMessage
method on the Form that is hosting the controls. The second is to implement
the IMessageFilter interface and register it with the static
AddMessageFilter method on the Application class. If you do the latter,
then the implementation will be called before the messages are dispatched to
the form (the applications message loop will pass to registered message
filters first).

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Hello,

I have designed a form in C#. There are several controls
on the form. I want to trap all the events at the form
level before they are passed on to the controls.

For eg : Suppose there are two buttons on the form. At any
moment one of the two buttons will be focused. When I
press any key I want to perform some default processing at
the Form level before the events are caught by the Buttons.

I want something simillar to what PreTranslateMessage does
for CWnd in MFC.

Thanks.


.
 
Joined
Oct 25, 2013
Messages
1
Reaction score
0
Hello Vibhesh,

have you found soln for this?
Am too facing the same problem.

Please help me.

Thank you.

Regards,
Manoj,
itzmanojds @ gmail.com
 

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