Search code examples
c#winformsimessagefilter

Howto disable filtering of a modal dialog's keypress events


I am running into a strange problem and seem to have to hunted down to the following root cause. Environment C# (.NET 2.0):

My code is using some vendor's framework and at one time opens a modal dialog. It seems that the framework is filtering on the Application's "Enter" Keypresses (probably by implementing IMessageFilter). As a consequence, closing my dialog by pressing the "OK" button leads to strange behaviour - closing via mouse-click on "OK" works fine. Changing the framework's code is unfortunately not an option. So I'd like to disable that the framework notices "Enter" (and probably "ESC") keypresses in my dialog. Does anyone know how this can be done?

EDIT:

I "solved" the issue. Please refer the Accepted Answer below.


Solution

  • I "solved" the issue. Here's the solution for future reference: setting the Form's (which was created in the modal dialog) FormBorderStyle property to FormBorderStyle.FixedDialog resolved the issue. Yes, this is a typical case of Cargo-Cult-Programming, but after thorough testing the fix works reliably.