473,783 Members | 2,577 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Can't delete an image that is in a picture box

I am having a problem with an application I am writing in vb.net 2003.

I display an image (JPG) on the screen using a Picturebox, loading it with
image.fromfile.

The user can select a key to delete the image.

If I try to delete it, it throws an error that the file is in use.

I tried the image.dispose() method, which allows me to copy the file and
MOST of the time delete the file, but not always. Sometimes it still throws
the in use error.

Any thoughts? Do I need to force garbage collection?

Thanks,

Tom
Apr 22 '06 #1
5 8680
Tom,

The most sufficient way is for this forever to read first the image in an
image and use that image for your picture box.

If you stream it direct you have to close it and than it is gone.

Cor

"Tom Scales" <tj******@gmail .com> schreef in bericht
news:xI******** *********@torna do.tampabay.rr. com...
I am having a problem with an application I am writing in vb.net 2003.

I display an image (JPG) on the screen using a Picturebox, loading it with
image.fromfile.

The user can select a key to delete the image.

If I try to delete it, it throws an error that the file is in use.

I tried the image.dispose() method, which allows me to copy the file and
MOST of the time delete the file, but not always. Sometimes it still
throws the in use error.

Any thoughts? Do I need to force garbage collection?

Thanks,

Tom

Apr 22 '06 #2
I can live with it being gone, as I don't need it anymore, but HOW do you
close it?

By read it into an image, do you mean:

Dim tmpImage as image.fromfile( "c:\image.j pg")
dim tmpBox as picturebox.imag e = tmpImage

I have tried every variation of this with no luck.

Tom
"Cor Ligthert [MVP]" <no************ @planet.nl> wrote in message
news:%2******** ********@TK2MSF TNGP02.phx.gbl. ..
Tom,

The most sufficient way is for this forever to read first the image in an
image and use that image for your picture box.

If you stream it direct you have to close it and than it is gone.

Cor

"Tom Scales" <tj******@gmail .com> schreef in bericht
news:xI******** *********@torna do.tampabay.rr. com...
I am having a problem with an application I am writing in vb.net 2003.

I display an image (JPG) on the screen using a Picturebox, loading it
with image.fromfile.

The user can select a key to delete the image.

If I try to delete it, it throws an error that the file is in use.

I tried the image.dispose() method, which allows me to copy the file and
MOST of the time delete the file, but not always. Sometimes it still
throws the in use error.

Any thoughts? Do I need to force garbage collection?

Thanks,

Tom


Apr 22 '06 #3
"Tom Scales" <tj******@gmail .com> schrieb:
I display an image (JPG) on the screen using a Picturebox, loading it with
image.fromfile.

The user can select a key to delete the image.

If I try to delete it, it throws an error that the file is in use.


Check out the code snippets at
<URL:http://dotnet.mvps.org/dotnet/code/graphics/#ImageNoLock>.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Apr 22 '06 #4
That looks perfect and seems to work. I can't imagine why the extra step is
necessary, since I am doing a dispose before the delete, but.....

Tom
"Herfried K. Wagner [MVP]" <hi************ ***@gmx.at> wrote in message
news:%2******** ********@TK2MSF TNGP05.phx.gbl. ..
"Tom Scales" <tj******@gmail .com> schrieb:
I display an image (JPG) on the screen using a Picturebox, loading it
with image.fromfile.

The user can select a key to delete the image.

If I try to delete it, it throws an error that the file is in use.


Check out the code snippets at
<URL:http://dotnet.mvps.org/dotnet/code/graphics/#ImageNoLock>.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Apr 22 '06 #5
For whatever reason, when you open and image and load it into a PictureBox,
VB leaves the file locked until the image is no longer being used. Check out
Bob Powell's GDI+ FAQ at this address: http://www.bobpowell.net/faqmain.htm
for a better explaination.
james

"Tom Scales" <tj******@gmail .com> wrote in message
news:%H******** ********@tornad o.tampabay.rr.c om...
That looks perfect and seems to work. I can't imagine why the extra step
is necessary, since I am doing a dispose before the delete, but.....

Tom
"Herfried K. Wagner [MVP]" <hi************ ***@gmx.at> wrote in message
news:%2******** ********@TK2MSF TNGP05.phx.gbl. ..
"Tom Scales" <tj******@gmail .com> schrieb:
I display an image (JPG) on the screen using a Picturebox, loading it
with image.fromfile.

The user can select a key to delete the image.

If I try to delete it, it throws an error that the file is in use.


Check out the code snippets at
<URL:http://dotnet.mvps.org/dotnet/code/graphics/#ImageNoLock>.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>


Apr 22 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2764
by: Doug van Vianen | last post by:
Although I have programmed for several decades I am new to Java. I decided to learn it to create Applets to use in web pages I make as a volunteer in the computer club at a seniors' centre. My current learning project is to divide a picture into rows and columns of squares, then redisplay the picture with these squares positioned randomly in the rows and columns. In an applet I have stored the original picture as an image, divided it...
0
1532
by: Ivan D. | last post by:
I am making a User Control in visual basic, it contains a Picture Box. To allow the image to change at design time I added a property. When changing a *normal* PictureBox Image at design time in the properties window the delete key usually sets the Image to nothing, but when I tried this with my new property it did not work. I have a feeling something needs to be added to the property statement in order to accept Nothing for any
4
4533
by: David | last post by:
hello to everybody... in of directories on my pc i have a list of su-directories, and in each directory theres an image "picture.ico"... so then my program is starting to run, i add a new listviewitem to my listview component then each item represents one of this subfolders, i also has imagelist, and with adding new item to listview i add image "picture.ico" to my imagelist... .... hope my english working well in explaining myself...
5
1502
by: JoskeXP | last post by:
Hi, When I use the following code I have a error that the file is in use If File.Exists("c:\RegistratieMD\images\" + Me.txtBarcode.Text + ".jpg") = True Then File.Delete("c:\RegistratieMD\images\" + Me.txtBarcode.Text+ ".jpg") End If How can I solve this problem
0
269
by: Penk | last post by:
I need a form to delete an image, in any format, that is shown in a control(picture edit), to replace with another image. I tried changing the archive that is showing the control, closing the form and then deleting the old image, but there's an error because the system says that the archive is in use. I need to replace this image, someone knows a way to close conections to the archive, or something like this? Thanks
3
7254
by: OptimalDesigns | last post by:
I'm trying to convert my website onto my CD drive (F:). Images are giving me problems due to lack of knowledge for sure. My image url looks like this ... file:///f:/ws_ftp/ode-cd/scripts/imagewrap.img? picture.image.url=file:///f:/ws_ftp/ode-cd/image/corp- entire_refinery.gif&picture.width.max=50&picture.height.max=0 and it doesn't work; ie. no picture shown on webpage in netscape 8.1. Is the part 'picture.image.url=file:///f:/ws_ftp/' ......
6
23404
by: DavidPr | last post by:
I made a little picture gallery for my website. The images and thumbnails are stored on the server and the information in a database. I know how to delete the information from the databasem, but how would I include instructions in the php script to also remove the thumb and image from the server? <?php if($_GET=="delete") { $sql = "DELETE FROM $table WHERE id=$id"; // code to delete images from server $result =...
3
2593
by: raghunadhs | last post by:
hi all! i have a picture box, in that picture box, there is a picture asume it as "pic1.bmp".. now i have made some changes in that picture. Now i want to load a picture to a image( my form consists of a picture box and a image also). like image1.picture=loadPicture(picture1.picture) ... but i know that this statement is invalid.... how can i do it? actually.. yesterday i learned how to make changes on a picture and how to save a...
3
1892
by: davidson1 | last post by:
Posted Date :- 17 feb 2008 Hello to everybody, I am very thankful to "the scripts" contributors. Their answers are really useful to me. Now i have a Question I am storing a image in webserver normally in c:\inetpub\wwwroot\picture folder
0
9480
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10315
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9946
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8968
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7494
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6737
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5379
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2877
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.