Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Exception-When minimized and restored

Exception-When minimized and restored

Scheduled Pinned Locked Moved C#
help
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    cloudking11966
    wrote on last edited by
    #1

    I am displaying images from a camera continuously in a PictureBox, it works fine, but when I minimize the window and restore again, it shows a cross symbol in picture box, as well as it throws argument exception, System.paint.getWidth(), etc, Please help, should I draw inside paint method or so, but I use Thread method to draw directly... Thanks in advance

    H S 2 Replies Last reply
    0
    • C cloudking11966

      I am displaying images from a camera continuously in a PictureBox, it works fine, but when I minimize the window and restore again, it shows a cross symbol in picture box, as well as it throws argument exception, System.paint.getWidth(), etc, Please help, should I draw inside paint method or so, but I use Thread method to draw directly... Thanks in advance

      H Offline
      H Offline
      Heath Stewart
      wrote on last edited by
      #2

      All interaction with a control should be done on the thread on which the control was created. The Control.InvokeRequired property and the Control.Invoke method are for this very thing. You could load the image in a separate thread, but when you assign the image to a PictureBox, for example, you should do it in the control's owner thread:

      void AssignImage(Image img)
      {
      if (!pictureBox1.InvokeRequired)
      {
      pictureBox1.Image = img;
      }
      else
      {
      MethodInfo setMethod = pictureBox1.GetType().GetProperty("Image").GetSetMethod();
      MethodInfoInvokeHandler d = new MethodInfoInvokeHandler(setMethod.Invoke);
      pictureBox1.Invoke(d, new object[] {pictureBox1, new object[] {img}});
      }
      }
      delegate object MethodInfoInvokeHandler(object obj, object[] parameters);

      Interacting with a control from a different thread causes unusual problems that differ from control to control and even between properties and methods for a single control. I'm not 100% sure this is the problem you're seeing but it's one possibility. This posting is provided "AS IS" with no warranties, and confers no rights. Software Design Engineer Developer Division Customer Product-lifecycle Experience Microsoft [My Articles] [My Blog]

      1 Reply Last reply
      0
      • C cloudking11966

        I am displaying images from a camera continuously in a PictureBox, it works fine, but when I minimize the window and restore again, it shows a cross symbol in picture box, as well as it throws argument exception, System.paint.getWidth(), etc, Please help, should I draw inside paint method or so, but I use Thread method to draw directly... Thanks in advance

        S Offline
        S Offline
        S Senthil Kumar
        wrote on last edited by
        #3

        What Heath said is probably what is happening, but you can also get those errors if you Dispose the image before the PictureBox gets a chance to draw it. Regards Senthil _____________________________ My Blog | My Articles | WinMacro

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups