MessageBox with KeyUp and Form with KeyPreview

O

Ori

Hi Guys,


Here is my problem, but maybe someone can help me with this.

Background:
1. Using C#.
2. I'm having a form which the KeyPreview is on (and must stay like
this) and I'm implementing some functions on the Key up event of some
controls and the form.


The Problem starts when I display a messagebox on the form. Now, when
the user click either "Enter" or "Esc" on the message box, the
messagebox is disappear on the KeyDown event and leaving the keyup
event to the parent form or to the control which was in focus before
we display the message box. Now remember, this problem occur only when
we use the keyboard (we don't have a mouse in the system, everything
is done with the keyboard).

Please note, it turns out that the "Enter" and the "Esc" keys doesn't
fire the keydown event so we can't look to whether we had a keydown on
the form before and only if we had a keydown we perform the keyup
event. We need to find another solution.

We looking to find a way to know that the keyup event occurred on the
messagebox and ignore it.

Does anyone know how to solve this problem?

Thanks,

Ori.
 
N

Nicholas Paldino [.NET/C# MVP]

Ori,

It sounds like a bug to me. If you can post a small example, I can get
it in the bug system at MS (MSDN product feedback center).

To work around your problem, it would be easy. Basically, on your form,
you have an instance method that would fire the message box. In it, it
would set a flag to true, indicating that the messagebox is shown, then show
the messagebox. In the keyup event handler, only perform the logic if the
flag is true, and always make sure to set the flag to false when done.

Hope this helps.
 

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