473,394 Members | 1,810 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Equivalent of PreTranslateMessage in C#

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.
Nov 15 '05 #1
2 7509
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]
- ni**************@exisconsulting.com

"Vibhesh" <Vi*************@windowmaker.com> wrote in message
news:49****************************@phx.gbl...
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.

Nov 15 '05 #2
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 PreProcessMessagemethod on the Form that is hosting the controls. The second is to implementthe IMessageFilter interface and register it with the staticAddMessageFilter method on the Application class. If you do the latter,then the implementation will be called before the messages are dispatched tothe form (the applications message loop will pass to registered messagefilters first).

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- ni**************@exisconsulting.com

"Vibhesh" <Vi*************@windowmaker.com> wrote in messagenews:49****************************@phx.gbl...
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.

.

Nov 15 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: John | last post by:
Is there an equivalent of COM on Linux that I can get through Python. My need is to have some sort of language independent component framework. I can think of CORBA but I have to have a server...
2
by: Michael Foord | last post by:
Please pardon my ignorance on this one - but I'm not certain how the sign bt is treated in python bitwise operators. I've trying to convert a javascript DES encryption routine into python. ...
3
by: Robert Dodier | last post by:
Hello, Here's a thought that I'm sure has already occurred to someone else, I just can't find any record of it yet. An XML document is just a more verbose and clumsy representation of an...
1
by: Vannela | last post by:
Is there any equivalent control in .NET for the Power builder DataWindow control? I am explaining the Datawindow architecture to some extent. Power Builder DataWindow Control has got different...
7
by: Tim Conner | last post by:
Hi, I am an ex-delphi programmer, and I having a real hard time with the following simple code (example ): Which is the equivalent to the following code ? var chars : PChar; sBack, s :...
10
by: karch | last post by:
How would this C# contruct be represented in C++/CLI? Or is it even possible? PolicyLevel level = (enumerator->Current) as PolicyLevel; Thanks, Karch
9
by: Alan Silver | last post by:
Hello, I'm converting some old VB6 code to use with ASP.NET and have come unstuck with the Asc() function. This was used in the old VB6 code to convert a character to its ASCII numeric...
14
by: grid | last post by:
Hi, I have a certain situation where a particular piece of code works on a particular compiler but fails on another proprietary compiler.It seems to have been fixed but I just want to confirm if...
2
by: Il Duce | last post by:
Hi, In MVC++ it is possible to override PreTranslateMessage. Is this not possible in a form under C# ? - H
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.