Picture Box Property Binding is Not Working

Odpovědět Picture Box Property Binding is Not Working

  • 14. dubna 2012 22:53
     
     
    Is there any reason why a picture box wouldn't be saving the image location and loading it into the box the next time the window loads through the picture box property binding 'ImageLocation'?

    Bgeo99

Všechny reakce

  • 14. dubna 2012 23:45
     
     Odpovědět

    Do you call PictureBox.Load?

    http://msdn.microsoft.com/en-us/library/zyc6weyd.aspx   PictureBox.Load

    Rudy   =8^D


    Mark the best replies as answers. "Fooling computers since 1971."

    http://thesharpercoder.blogspot.com/

  • 15. dubna 2012 5:22
     
     

    Do you call PictureBox.Load?

    http://msdn.microsoft.com/en-us/library/zyc6weyd.aspx   PictureBox.Load

    Rudy   =8^D


    Mark the best replies as answers. "Fooling computers since 1971."

    http://thesharpercoder.blogspot.com/


    How do I use the PictureBox.Load to fix the property binding, which is different, and where? Does it belong in the form's load sub, or is it in the picturebox private sub?

    Bgeo99


    • Upravený Bgeo99 15. dubna 2012 5:26
    •  
  • 15. dubna 2012 16:21
     
     

    First of all, let's dismiss the misconception that setting Image.Location property "binds" an image file to the control.  It doesn't, which you have obviously discovered. 

    As for your question about when to call Load, I suggest that you call it whenever you want to see the image.  Make sure that you have assigned a value to the Location property before you call Load, though.  It wouldn't make sense to call Load when you have not told the control what to load.

    Also, make sure that the control has been assigned a handle from the OS before you call load.  A handle means that the control has been instantiated in memory, which means that the call to Load can actually store the image somewhere.  Having a handle means the object is consuming video memory, in addition to consuming space as an object instance on the Managed Heap.

    In other words, you cannot do it during the InitalizeComponent method.  You cannot do it within the Form.Load event because all of the Form controls are not guaranteed to have handles when that event handler is actually called, althought some controls frequently will.  The controls almost certainly won't have handles when the event is fired. 

    Only the Form is guaranteed to have a handle during Form.Load.  All of the Form's controls are guaranteed to have their handles when the Form.Shown event is fired.  They would have to have them by that point.  Controls cannot be displayed if they do not have a handle to unmanaged video memory.

    Rudy   =8^D


    Mark the best replies as answers. "Fooling computers since 1971."

    http://thesharpercoder.blogspot.com/