除了一个令人讨厌的bug之外,这种方法很完美:当我点击“从图像剪切”按钮并拖动一个正方形时,它会很好地获取文本框中的信息.然后,如果我点击下一个文本框,它会很顺利,但如果我使用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 layer)
>在System.Windows.Forms.Control.WmPaint(消息& m)
>在System.Windows.Forms.Control.WndProc(消息& m)
> at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
>在System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
> at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd,Int32 msg,IntPtr wparam,IntPtr lparam)
>在System.Windows.Forms.UnsafeNativeMethods.dispatchMessageW(MSG& msg)
> at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.imsoComponentManager.FPushMessageLoop(IntPtr dwComponentID,Int32 reason,Int32 pvLoopData)
> at System.Windows.Forms.Application.threadcontext.RunMessageLoopInner(Int32 reason,ApplicationContext context)
> at System.Windows.Forms.Application.threadcontext.RunMessageLoop(Int32 reason,ApplicationContext context)
>在Microsoft.VisualBasic.applicationservices.WindowsFormsApplicationBase.OnRun()
>在Microsoft.VisualBasic.applicationservices.WindowsFormsApplicationBase.DoApplicationModel()
>在Microsoft.VisualBasic.applicationservices.WindowsFormsApplicationBase.Run(String [] commandLine)
>在ORC_Testing.My.MyApplication.Main(String [] Args)in 17d14f5c-a337-4978-8281-53493378c1071.vb:第81行
> at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly,String [] args)
>在System.AppDomain.ExecuteAssembly(String assemblyFile,Evidence assemblySecurity,String [] args)
>在Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
> at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
> at System.Threading.ExecutionContext.Run(ExecutionContext executionContext,ContextCallback callback,Object state,Boolean ignoreSyncCtx)
>在System.Threading.ExecutionContext.Run(ExecutionContext executionContext,ContextCallback回调,对象状态)
>在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.
解决方法
Dim myImage As Image = Image.FromFile("file path") PictureBox1.Image = myImage PictureBox1.Refresh() ' This works myImage.dispose() PictureBox1.Refresh() ' This throws an exception because it tries to access the disposed Image object
PictureBox控件会在处理时自动处理图像,因此您无需担心自己处理它.您应该处理图像的唯一时间是您不将它们提供给任何其他对象以供以后使用.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。