我创建了一个干净的 WindowsFormsApplication 解决方案,ToolStrip
在主窗体中添加了一个,并在其上放置了一个按钮。我还添加了一个OpenFileDialog
,因此Click
事件ToolStripButton
如下所示:
private void toolStripButton1_Click(object sender, EventArgs e)
{
openFileDialog1.ShowDialog();
}
我没有更改任何其他属性或事件。
好笑的是当我双击的时候ToolStripButton
(第二次点击一定很快,在对话框打开之前),然后取消两个对话框(或者选择一个文件,没关系)然后在客户区点击在主窗体中,NullReferenceException
应用程序崩溃(帖子末尾附有错误详细信息)。请注意,该Click
事件已实施,DoubleClick
而未实施。
更奇怪的OpenFileDialog
是,当替换为任何用户实现的表单时,ToolStripButton
阻止被点击两次。
我在最新更新的Windows 7 Professional(来自 MSDNAA)上使用 VS2008 和 .NET3.5。我没有更改 VS 中的许多选项(仅字体大小、工作区文件夹和行号)。
有谁知道如何解决这个问题?它在我的机器上是 100% 可复制的,在其他机器上也可以吗?
我能想到的一种解决方案是在调用之前禁用按钮OpenFileDialog.ShowDialog()
,然后重新启用按钮(但这并不好)。还有其他想法吗?
现在承诺的错误详细信息:
System.NullReferenceException 未处理
Message="对象引用未设置为对象的实例。"
Source="System.Windows.Forms"
StackTrace:在 System.Windows.Forms.UnsafeNativeMethods.PeekMessage 的 System.Windows.Forms.NativeWindow.WindowClass.Callback(IntPtr hWnd, Int32 msg
, IntPtr wparam, IntPtr lparam)
HandleRef hwnd, Int32 msgMin, Int32 msgMax, Int32 remove)
在 System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
在 System.Windows.Forms .Application.ThreadContext.RunMessageLoopInner(Int32 原因,
在 System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
在 System.Windows.Forms.Application.Run(Form mainForm)
在 WindowsFormsApplication1.Program.Main() w C:\Users\Marchewek\Desktop \Workspaces\VisualStudio\WindowsFormsApplication1\Program.cs:第 20 行
System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
在 Microsoft.VisualStudio
System.Threading.ThreadHelper.ThreadStart_Context(对象状态)处的.HostingProcess.HostProc.RunUsersAssembly( )
在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
在 System.Threading.ThreadHelper.ThreadStart()
InnerException: