Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9005403
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T01:08:08+00:00 2026-06-16T01:08:08+00:00

I have a form where the user can first scan to a bitmap. When

  • 0

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.

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” ArgumentException 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.

I tried to override the tab key (just for debugging) 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 it still crashes.

Any suggestions about what’s wrong? Since I don’t know where to begin debugging I can’t tell what code to show.

EDIT 1

Here is the stack trace for the ArgumentException that gets thrown:

  • at System.Drawing.Image.get_Width()
  • at System.Drawing.Image.get_Size()
  • at System.Windows.Forms.PictureBox.ImageRectangleFromSizeMode(PictureBoxSizeMode mode)
  • at System.Windows.Forms.PictureBox.OnPaint(PaintEventArgs pe)
  • at System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer)
  • at System.Windows.Forms.Control.WmPaint(Message& m)
  • at System.Windows.Forms.Control.WndProc(Message& m)
  • at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
  • at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
  • at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
  • at 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)
  • at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
  • at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
  • at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
  • at ORC_Testing.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
  • at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
  • at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
  • at 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)
  • at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
  • at System.Threading.ThreadHelper.ThreadStart()

EDIT 2

Here is how I’m scanning/loading the 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.
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T01:08:09+00:00Added an answer on June 16, 2026 at 1:08 am

    Your problem is likely that, at some point, you are calling the Dispose method on one of your Image objects. When you call Image.Dispose, it deletes the underlying image data from memory, so the Image object still exists, but is invalid because it no longer contains an actual image. When you set the PictureBox.Image property to a loaded Image object, the PictureBox control assumes that the Image object will remain valid so that it can reuse it later any time the control needs to repaint itself to the screen. For instance:

    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
    

    The PictureBox control will automatically dispose of the image for you when it is disposed, so you don’t need to worry about disposing it yourself. The only time you should be disposing your images is when you are not giving them to any other objects for later use.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a MOSS workflow where on the first form, the user can choose
I have a form where a user can enter the number of students that
I have a form on a page that a user can use to create
I have a page which displays a form that a logged-in user can use
I have a field that a user can input first and last name to
I have a referral form that a user can refer friends for membership. The
I have a registration form that a user can access via invitation. For example,
I have a form with a number of text boxes for user input (this
I have one page form done with Spring MVC. User has to register first
I have a simple form where a user can choose a colour and then

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.