Reputation: 8350
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 ?
Upvotes: 0
Views: 3591
Reputation:
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().
Upvotes: 2
Reputation:
I think you can create your own form and use the mymessageboxform.show() method, and check its dialogue result.
Upvotes: 0
Reputation: 32377
You'll want to make your application single instance so it can only be started once.
Upvotes: -1
Reputation: 17081
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.
Upvotes: 1