I have a form where the user can first scan into a bitmap. When the scan is completed and the bitmap is loaded, I have 4 text fields, which are then included. Next to each text box there is a "Cut from image" button. When the user clicks the button, they can click and drag the bitmap to get the selected text using MODI.
This works fine, except for one annoying error: when I click the "Cut Image" button and drag the square, it gets the information in the text box. Then, if I click on the next text field, it will be very good, but if I use the tab key to leave the field, I get an "Parameter is invalid" ArgumentException , and it does not show any help for where the trouble code is. I can post to the form without any problems, but after scanning the bitmap it resets, like 9 out of 10 times, when I use the tab key.
I tried to override the tab key (for debugging only) using this:
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
... but he still falls.
Any suggestions on what happened? Since I don’t know where to start debugging, I can’t say what code to show.
EDIT 1
Here is the stack trace for an ArgumentException that throws:
- in System.Drawing.Image.get_Width ()
- in System.Drawing.Image.get_Size ()
- in System.Windows.Forms.PictureBox.ImageRectangleFromSizeMode (PictureBoxSizeMode mode)
- in System.Windows.Forms.PictureBox.OnPaint (PaintEventArgs pe)
- in System.Windows.Forms.Control.PaintWithErrorHandling (PaintEventArgs e, Int16 layer)
- in System.Windows.Forms.Control.WmPaint (Message & m)
- in System.Windows.Forms.Control.WndProc (Message & m)
- in System.Windows.Forms.Control.ControlNativeWindow.OnMessage (Message & m)
- in System.Windows.Forms.Control.ControlNativeWindow.WndProc (Message & m)
- in System.Windows.Forms.NativeWindow.DebuggableCallback (IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
- in System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW (MSG & msg)
- in System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop (IntPtr dwComponentID, reason Int32, Int32 pvLoopData)
- in System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner (reason Int32, context ApplicationContext)
- in System.Windows.Forms.Application.ThreadContext.RunMessageLoop (Int32 reason, ApplicationContext context)
- at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun ()
- at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel ()
- at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run (String [] commandLine)
- in ORC_Testing.My.MyApplication.Main (String [] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb: line 81
- in System.AppDomain._nExecuteAssembly (assembly RuntimeAssembly, String [] args)
- in System.AppDomain.ExecuteAssembly (String assemblyFile, Evidence assemblySecurity, String [] args)
- at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly ()
- in System.Threading.ThreadHelper.ThreadStart_Context (object state)
- in System.Threading.ExecutionContext.Run (ExecutionContext executeContext, ContextCallback callback, object state, Boolean ignoreSyncCtx)
- in System.Threading.ExecutionContext.Run (ExecutionContext executeContext, ContextCallback callback, object state)
- in System.Threading.ThreadHelper.ThreadStart ()
EDIT 2
This is how I scan / upload an image:
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.
source share