ContextMenuStrip错误 [英] ContextMenuStrip bug

查看:104
本文介绍了ContextMenuStrip错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ContextMenuStrip错误:在主窗体的ContextMenuStrip上触发ToolStripMenuItem,同时仍显示模态对话框-导致已经可见的窗体无法显示为模态...

当模式对话框"处于活动状态时,主窗体仍会接受并触发ContextMenuStrip上驻留的ToolStripItem事件.

这是一个非常令人沮丧且令人无法接受的行为.

当我认为表单的设计器代码已损坏时,被引导从头开始重建应用程序的主表单,但是问题再次出现了! :mad:

我很惊讶在任何编程论坛上都找不到关于此问题的讨论.我可能是唯一遇到此明显错误的人吗? :confused:

我真的很感激一个解决方案或解决方法. :rose:
这东西让我把头发累了! :sigh:

这与Visual Studio 2008 SP1 .NET 3.5有关.

重现:

启动一个项目,然后向该项目添加一个About Box.
将ContextMenuStrip添加到主窗体.
将一个MenuItem(对于ShortcutKeys属性使用"F1",对于Text属性使用"About")添加到ContextMenuStrip.
在主窗体中添加一个ToolStrip.
将一个DropDownButton添加到ToolStrip.
将DropDownButton的DropDown属性更新为ContextMenuStrip.

将以下代码应用于主要形式:-


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()
		{
			InitializeComponent();
		}

		AboutDlg aboutDlg = new AboutDlg();

		private void toolStripMenuItem1_Click(object sender, EventArgs e)
		{
			aboutDlg.ShowDialog(this);
		}

		private void toolStripMenuItem2_Click(object sender, EventArgs e)
		{
			Close();
		}
	}
}



现在,运行程序并按F1键显示对话框,然后在模式对话框"仍处于活动状态时按F1键....-繁荣-InvalidOperationException



Now, run the program and press F1 to show the dialog, and press F1 while the "modal dialog" is still active ...and boom - InvalidOperationException

推荐答案

try
{
    aboutDlg.ShowDialog(this);
}
catch
{

}


这将使错误不会出现,但是不建议您这样做,因为try and catch的全部目的是识别不断上升的异常. MSDN [


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[^]


这篇关于ContextMenuStrip错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆