【发布时间】:2012-12-04 10:38:00
【问题描述】:
我有一个表单,用户可以先扫描到位图。扫描完成并加载位图后,我有 4 个文本框被启用。在每个文本框旁边,我有一个名为“从图像剪切”的按钮。当用户单击按钮时,他们可以在位图中单击并拖动以使用 MODI 获取选定的文本。
除了一个烦人的错误外,这很完美:当我单击“从图像剪切”按钮并拖动一个正方形时,它会将信息很好地发送到文本框。然后,如果我单击下一个文本框,它会非常顺利,但是如果我使用 Tab 键离开该字段,我会得到一个“参数无效”ArgumentException 并且它没有显示任何帮助发生崩溃的代码。我可以毫无问题地在表单中切换,但是一旦扫描了位图,当我使用 Tab 键时,它会像 10 次中的 9 次一样崩溃。
我尝试使用以下方法覆盖 tab 键(仅用于调试):
Protected Overrides Function ProcessTabKey(ByVal forward As Boolean) As Boolean
MsgBox("TAB is currently disabled!")
Return False 'Tried True as well, just in case
End Function
...但它仍然崩溃。
有什么建议吗?因为我不知道从哪里开始调试,所以我不知道要显示什么代码。
编辑 1
这是被抛出的ArgumentException 的堆栈跟踪:
- 在 System.Drawing.Image.get_Width() 处
- 在 System.Drawing.Image.get_Size()
- 在 System.Windows.Forms.PictureBox.ImageRectangleFromSizeMode(PictureBoxSizeMode 模式)
- 在 System.Windows.Forms.PictureBox.OnPaint(PaintEventArgs pe)
- 在 System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 层)
- 在 System.Windows.Forms.Control.WmPaint(Message& m)
- 在 System.Windows.Forms.Control.WndProc(Message& m)
- 在 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
- 在 System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
- 在 System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
- 在 System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
- 在 System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
- 在 System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 原因,ApplicationContext 上下文)
- 在 System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 原因,ApplicationContext 上下文)
- 在 Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
- 在 Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
- 在 Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
- 在 ORC_Testing.My.MyApplication.Main(String[] Args) 在 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
- 在 System.AppDomain._nExecuteAssembly(RuntimeAssembly 程序集,String[] args)
- 在 System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
- 在 Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
- 在 System.Threading.ThreadHelper.ThreadStart_Context(对象状态)
- 在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
- 在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
- 在 System.Threading.ThreadHelper.ThreadStart()
编辑 2
这是我扫描/加载图像的方式:
Dim filename As Collection
filename = TwainHandler.ScanImages("c:\scan\", "tif")
Dim ScannedFile As Image = Image.FromFile(filename(1))
PictureBox1.Image = ScannedFile
PictureBox1.Width = ScannedFile.Width
' etc.
【问题讨论】:
-
你有异常的调用栈吗?你知道它在代码中的哪一行失败了吗?你能展示那部分代码吗?
-
是的,但由于我并不真正进入 VS,所以我不知道从哪里真正开始。消息:“参数无效”。来源:“System.Drawing”。你想要“StackTrace”吗?
-
哦,不。我真的看不出它在代码中的哪个位置失败了。
-
您是否使用调试器运行应用程序?如果是这样,应该有一种方法可以显示异常的详细信息并显示堆栈跟踪。至少,堆栈跟踪会显示它发生在哪个方法中。
-
尝试删除您在任何
Image对象上调用Dispose的任何地方,看看错误是否消失。
标签: vb.net winforms bitmap keypress modi