0

I have a created a custom keyboard shortcut for my application, when the user press combination keys of CTRL + ALT + Q, i show a messagebox "Are you sure you want to log out ?" Then if clicked YES, i log out of the application.

Problem : I want to make sure that, only once instance of message box shows. No matter how many times the user presses the shortcut.

currently it shows multiple message box, on pressing multiple shortcuts.

How to overcome this ?

3
  • AFAIK, msgbox are supposed to be modal. How is the custom keyboard shortcut set? Is it same as menu shortcuts (Ctrl+S = File->Save)? Commented Jul 30, 2009 at 3:11
  • 3
    Why not make the message box modal? Application cannot be used until message box dialog has been closed? Commented Jul 30, 2009 at 3:11
  • How are you creating the shortcut? Are you using System.Windows.Forms.MessageBox or something else? Commented Jul 31, 2009 at 2:03

5 Answers 5

2

From MSDN

A message box is a modal dialog box, which means no input (keyboard or mouse click) can occur except to objects on the modal form. The program must hide or close a modal form (typically in response to some user action) before input to another form can occur.

File a bug on connect.microsoft.com !


Taking ck's comment into consideration...If you are showing a custom dialog (form) then you need to invoke the form using Form.ShowDialog() and not Show().

Sign up to request clarification or add additional context in comments.

2 Comments

This must mean he has a custom form for confirmation, as no MS software would ever have any bugs...?
Even though I think "no MS software would ever have any bugs" is debatable I think you have a point! The question does not say that he is using the MessageBox class.
1

A quick and dirty way would be to have a class level boolean variable that tracks when the user is trying to exit. If they are, it's set to true, and your routine to display the dialog box can check this flag, then return without doing anything.

Comments

0

Seems like Singleton Pattern is your option.

1 Comment

The question is about MessageBox.Show, which is a static method of a static class MessageBox. There are no objects involved here, at all.
0

I think you can create your own form and use the mymessageboxform.show() method, and check its dialogue result.

Comments

-1

You'll want to make your application single instance so it can only be started once.

Single Instance App

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.