title: PictureBox throws "Parameter is not valid" ArgumentException upon tab keypress
body: <p>I have a form where the user can first scan to a bitmap.  When scan is done, and the bitmap is loaded, I have 4 text boxes that are then enabled. Next to each text box, I have a button called "Cut from image".  When the user clicks the button, they can click and drag in the bitmap to get the selected text using MODI. </p>
  
  <p>This works perfect except for one annoying bug: When I click a "Cut from image" button and drag a square, it gets the information nicely to the text box.  Then, if i click to the next text box, it goes very well, but if I use the tab key to leave the field, I get a "Parameter is not valid" <code>ArgumentException</code> and it does not show any help for where in the code the crash is made.  I can tab around in the form with no problems at all, but once the bitmap is scanned, it crashes like 9 out of 10 times when I use the tab key.</p>
  
  <p>I tried to override the tab key (just for debugging) using this:</p>
  
  <pre><code>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
  </code></pre>
  
  <p>...but it still crashes.</p>
  
  <p>Any suggestions about what's wrong? Since I don't know where to begin debugging I can't tell what code to show. </p>
  
  <p><strong>EDIT 1</strong></p>
  
  <p>Here is the stack trace for the <code>ArgumentException</code> that gets thrown:</p>
  
  <ul>
  <li>at System.Drawing.Image.get_Width()</li>
  <li>at System.Drawing.Image.get_Size()</li>
  <li>at System.Windows.Forms.PictureBox.ImageRectangleFromSizeMode(PictureBoxSizeMode mode)</li>
  <li>at System.Windows.Forms.PictureBox.OnPaint(PaintEventArgs pe)</li>
  <li>at System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer)</li>
  <li>at System.Windows.Forms.Control.WmPaint(Message&amp; m)</li>
  <li>at System.Windows.Forms.Control.WndProc(Message&amp; m)</li>
  <li>at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message&amp; m)</li>
  <li>at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message&amp; m)</li>
  <li>at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)</li>
  <li>at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG&amp; msg)</li>
  <li>at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)</li>
  <li>at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)</li>
  <li>at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)</li>
  <li>at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()</li>
  <li>at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()</li>
  <li>at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)</li>
  <li>at ORC_Testing.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81</li>
  <li>at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)</li>
  <li>at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)</li>
  <li>at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()</li>
  <li>at System.Threading.ThreadHelper.ThreadStart_Context(Object state)</li>
  <li>at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)</li>
  <li>at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)</li>
  <li>at System.Threading.ThreadHelper.ThreadStart()</li>
  </ul>
  
  <p><strong>EDIT 2</strong></p>
  
  <p>Here is how I'm scanning/loading the image:</p>
  
  <pre><code>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.
  </code></pre>