Click here to Skip to main content
13,598,644 members
Rate this:
Please Sign up or sign in to vote.
See more:
ContextMenuStrip bug: ToolStripMenuItem fires on main form's ContextMenuStrip, while a modal dialog is still showing - resulting in "Form that is already visible cannot be displayed as a modal...

When a "modal dialog" is active, the main form still accepts and fires ToolStripItem events residing on a ContextMenuStrip.

This is a very frustrating and unacceptable behaviour.

When I thought my form's designer code had become corrupt, I was led to rebuild my application's main form from scratch, but the problem re-emerged! :mad:

I was surprised to find no discussing about this problem at any programming forum. Could I possible be the only person to come across this so-obvious bug? :confused:

I would really appreciate a solution or workaround. :rose:
This thing has had me tiring my hair out! :sigh:

This is regarding Visual Studio 2008 SP1 .NET 3.5.

To reproduce:

Start a project and add an About Box to the project.
Add a ContextMenuStrip to the main form.
Add a MenuItem (with "F1" for the ShortcutKeys property, and "About" for the Text property) to the ContextMenuStrip.
Add a ToolStrip to the main form.
Add a DropDownButton to the ToolStrip.
Update DropDown property of DropDownButton to be the ContextMenuStrip.

Apply the following code to the main form:-

namespace WindowsFormsApplication1
	public partial class MainFrm : Form
		public MainFrm()

		AboutDlg aboutDlg = new AboutDlg();

		private void toolStripMenuItem1_Click(object sender, EventArgs e)

		private void toolStripMenuItem2_Click(object sender, EventArgs e)

Now, run the program and press F1 to show the dialog, and press F1 while the "modal dialog" is still active ...and boom - InvalidOperationException
Posted 5-May-10 5:06am
Updated 5-May-10 5:44am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1



This will make the error not appear however this is not recommended as the whole purpose of try and catch is to identify rising Exceptions. MSDN[^]
Cnight Stalker 5-May-10 11:42am
Thanks for your efforts, but the problem remains.

I have various functions located on ContextMenuStrip, including 'MainFrm.Close()'. When a user presses the ShortcutKey for closing the main form, that event must not fire, not while there is a modal dialog. This is the whole point of a modal dialog - to suspend main form input, until the dialog is closed.

Unfortunately, your solution does not result the problem.
4277480 5-May-10 11:46am
My answer was based on your question which doesn't mention the shortcut key for closing the form?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Cookies | Terms of Service
Web03-2016 | 2.8.180621.3 | Last Updated 5 May 2010
Copyright © CodeProject, 1999-2018
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100