igoor
asked on
propertygrid file reference problem.
I have a windows application that has a propertygrid control and the selected object is a picturebox control.
I set the the Image property to a file on my HD, and the picture box displays the image.
But the propertygrid maintains a reference to the file on the HD, which i don't want as i intend to destroy the image after it is assigned to the picture box.
is there a way around this?
thanks
igoor
I set the the Image property to a file on my HD, and the picture box displays the image.
But the propertygrid maintains a reference to the file on the HD, which i don't want as i intend to destroy the image after it is assigned to the picture box.
is there a way around this?
thanks
igoor
ASKER
on further inspection it is the picture box control that holds the reference.
the error i get when i try and delete the file is "There has been a sharing violation. the source or desitnation file may be in use."
basically what i would like to be able to do, via the propertygrid, is to set the image property of the picturebox control to a snapshot/copy of an image file. so that the image file is no longer required/referenced.
to replicate,
create a window app in .net
add a picturebox control and a propertygrid control
set the propertygrids selectedobject to the picturebox.
run the application.
set the image property in the propertygrid to an image file.
now try delete the image file - cant do it.
i would like to be able to delete the file from the hard drive, but remain in memory in my app.
the error i get when i try and delete the file is "There has been a sharing violation. the source or desitnation file may be in use."
basically what i would like to be able to do, via the propertygrid, is to set the image property of the picturebox control to a snapshot/copy of an image file. so that the image file is no longer required/referenced.
to replicate,
create a window app in .net
add a picturebox control and a propertygrid control
set the propertygrids selectedobject to the picturebox.
run the application.
set the image property in the propertygrid to an image file.
now try delete the image file - cant do it.
i would like to be able to delete the file from the hard drive, but remain in memory in my app.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks for your help.
but i have to use the propertygrid to set the image object.
maybe i could do something in the PropertyValueChanged event of the propertygrid to set the image?!!
but i have to use the propertygrid to set the image object.
maybe i could do something in the PropertyValueChanged event of the propertygrid to set the image?!!
ASKER
i have tried to use the PropertyValueChanged to call some similar to the code you described earlier.
as follows:
private void propertyGrid1_PropertyValu eChanged(o bject s, System.Windows.Forms.Prope rtyValueCh angedEvent Args e) {
if(e.ChangedItem.Label == "Image"){
if(pictureBox1.Image !=null){
Image diskImg = pictureBox1.Image;
MemoryStream mem = new MemoryStream();
diskImg.Save(mem,System.Dr awing.Imag ing.ImageF ormat.Bmp) ;
Image memImg = new Bitmap(mem);
this.pictureBox1.Image.Dis pose();
diskImg.Dispose();
pictureBox1.Image = memImg;
}
}
}
but it seems as if the picturebox image isn't getting disposed of.
any ideas?
as follows:
private void propertyGrid1_PropertyValu
if(e.ChangedItem.Label == "Image"){
if(pictureBox1.Image !=null){
Image diskImg = pictureBox1.Image;
MemoryStream mem = new MemoryStream();
diskImg.Save(mem,System.Dr
Image memImg = new Bitmap(mem);
this.pictureBox1.Image.Dis
diskImg.Dispose();
pictureBox1.Image = memImg;
}
}
}
but it seems as if the picturebox image isn't getting disposed of.
any ideas?
ASKER
it just started working.
Thanks again for your help.
Thanks again for your help.
I think you could use the event handler to switch the image from a disk based one to a memory based one. I am still working on it, will let you know tomorrow morning. It's late over here.
Oh...great :) :) Just be sure that it is working all the time, there maybe a timing issue involved with respect to the garbage collector.
Let me know if you have problems, i'll sort them out.
Let me know if you have problems, i'll sort them out.
ASKER
ah your right.
it is not a 100%.
works 9 times out of 10 approx.
it is not a 100%.
works 9 times out of 10 approx.
ASKER
managed to sort it now by calling
GC.Collect()
which forces the garbage collection.
GC.Collect()
which forces the garbage collection.
Great :) :)
Are you getting any errors at runtime?..If so then please specify.