473,771 Members | 2,394 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Deleting images after viewed thru a picturebox

Hi,

I'm writing an app to maintain products. The products are listed in a
listbox and when I click a product in a listbox some info of that product is
shown including a picture of the product.

I do this by using the image.fromfile function: pbProduct.Image =
Image.FromFile( myImagePath & productkey & ".jpg")

Now I'm building the option to delete a product. When a product is selected
in the listbox a Delete button is activated. Pressing the Delete Button
deletes the product row from the database and should delete the picture from
the picturefolder, but.... It can't because it says it's in use. It's in use
by the picturebox (pbProduct). I've tested that because when I don't load
the picture when selecting the product, I can delete it (database row +
image file)

I've tried the pbProduct.Image .Dispose, setting the image to Nothing, but
none of it seems to work. Even loading a different image into the picture
box before deleting. Nothing worked.

Any ideas?

Thanks
Bart

Nov 30 '07 #1
4 1750
Hi,

I just tried your re-create your problem and pbProduct.Image .Dispose()
worked fine for me.

Is it possible that when you tried to dispose it then you loaded it more
than once, i.e. if your listbox event just performs that line then if
you click the same product more than once then you are loading it twice
without disposing the first one.

Try adding this before pbProduct.Image = Image.FromFile( myImagePath &
productkey & ".jpg")

Try
pbProduct.Image .Dispose()
Catch
End Try

HTH
Chris.

Bart Steur wrote:
Hi,

I'm writing an app to maintain products. The products are listed in a
listbox and when I click a product in a listbox some info of that product is
shown including a picture of the product.

I do this by using the image.fromfile function: pbProduct.Image =
Image.FromFile( myImagePath & productkey & ".jpg")

Now I'm building the option to delete a product. When a product is selected
in the listbox a Delete button is activated. Pressing the Delete Button
deletes the product row from the database and should delete the picture from
the picturefolder, but.... It can't because it says it's in use. It's in use
by the picturebox (pbProduct). I've tested that because when I don't load
the picture when selecting the product, I can delete it (database row +
image file)

I've tried the pbProduct.Image .Dispose, setting the image to Nothing, but
none of it seems to work. Even loading a different image into the picture
box before deleting. Nothing worked.

Any ideas?

Thanks
Bart
Nov 30 '07 #2
In addition, you'll still need to dispose it before you delete the file.

Chris Diver wrote:
Hi,

I just tried your re-create your problem and pbProduct.Image .Dispose()
worked fine for me.

Is it possible that when you tried to dispose it then you loaded it more
than once, i.e. if your listbox event just performs that line then if
you click the same product more than once then you are loading it twice
without disposing the first one.

Try adding this before pbProduct.Image = Image.FromFile( myImagePath &
productkey & ".jpg")

Try
pbProduct.Image .Dispose()
Catch
End Try

HTH
Chris.

Bart Steur wrote:
>Hi,

I'm writing an app to maintain products. The products are listed in a
listbox and when I click a product in a listbox some info of that
product is shown including a picture of the product.

I do this by using the image.fromfile function: pbProduct.Image =
Image.FromFile (myImagePath & productkey & ".jpg")

Now I'm building the option to delete a product. When a product is
selected in the listbox a Delete button is activated. Pressing the
Delete Button deletes the product row from the database and should
delete the picture from the picturefolder, but.... It can't because it
says it's in use. It's in use by the picturebox (pbProduct). I've
tested that because when I don't load the picture when selecting the
product, I can delete it (database row + image file)

I've tried the pbProduct.Image .Dispose, setting the image to Nothing,
but none of it seems to work. Even loading a different image into the
picture box before deleting. Nothing worked.

Any ideas?

Thanks
Bart
Nov 30 '07 #3
Placing a dispose before loading the image did the trick. Thanks.
"Chris Diver" <cR************ *******@gmail.c omwrote in message
news:%2******** **********@TK2M SFTNGP03.phx.gb l...
Hi,

I just tried your re-create your problem and pbProduct.Image .Dispose()
worked fine for me.

Is it possible that when you tried to dispose it then you loaded it more
than once, i.e. if your listbox event just performs that line then if
you click the same product more than once then you are loading it twice
without disposing the first one.

Try adding this before pbProduct.Image = Image.FromFile( myImagePath &
productkey & ".jpg")

Try
pbProduct.Image .Dispose()
Catch
End Try

HTH
Chris.

Bart Steur wrote:
>Hi,

I'm writing an app to maintain products. The products are listed in a
listbox and when I click a product in a listbox some info of that product
is shown including a picture of the product.

I do this by using the image.fromfile function: pbProduct.Image =
Image.FromFile (myImagePath & productkey & ".jpg")

Now I'm building the option to delete a product. When a product is
selected in the listbox a Delete button is activated. Pressing the Delete
Button deletes the product row from the database and should delete the
picture from the picturefolder, but.... It can't because it says it's in
use. It's in use by the picturebox (pbProduct). I've tested that because
when I don't load the picture when selecting the product, I can delete it
(database row + image file)

I've tried the pbProduct.Image .Dispose, setting the image to Nothing, but
none of it seems to work. Even loading a different image into the picture
box before deleting. Nothing worked.

Any ideas?

Thanks
Bart

Nov 30 '07 #4
"Bart Steur" <so*****@xs4all .nlschrieb:
I'm writing an app to maintain products. The products are listed in a
listbox and when I click a product in a listbox some info of that product
is shown including a picture of the product.

I do this by using the image.fromfile function: pbProduct.Image =
Image.FromFile( myImagePath & productkey & ".jpg")

Now I'm building the option to delete a product. When a product is
selected in the listbox a Delete button is activated. Pressing the Delete
Button deletes the product row from the database and should delete the
picture from the picturefolder, but.... It can't because it says it's in
use. It's in use by the picturebox (pbProduct).
\\\
Using OldImage As Image = Me.PictureBoxPr oduct.Image
Me.PictureBoxPr oduct.Image = My.Resources.De faultProductIma ge
End Using
Kill(<file name>)
///

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

Nov 30 '07 #5

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

Similar topics

10
1881
by: cosmic foo | last post by:
I have a page with about 100 images of about 10k each. where a typical img tag looks like this, <img src="item001.jpg" height="70" alt="" onMouseOver="showPic(this)" border="0"> Not all the images need to be viewed at once, depending on what category is selected, only about 10 images are seen at any one time. I hide and show categories of images by setting a div container display:none/block or visibility:hidden/visible. Even though the...
1
1075
by: Tony | last post by:
Hi all, My problem is, I have created a form with a background Image assigned to it. On top of it, I have an instance which is a subclass of PictureBox. I overrided the PictureBox OnMouseMove method so that it moves along with the mouse movement. Though there is no problem when moving the PictureBox, as the PictureBox moves, the form's background Image doesn't update the area under the PictureBox, there are still some images remain on...
18
7444
by: Andrew Christiansen | last post by:
Hey all. The images I create in photoshop with semi-transparent pixels (for instance in Photoshop text with a dropshadow with a transparent canvas) I've been saving in PNG format and then using them in my VB.NET app using the picturebox control. I was really happy when I learned that you could use PNG images in VB.NET so your images could blend in with the form's background color. But, is PNG the ideal image format to use with these...
0
1480
by: Marcus Kwok | last post by:
I have written a class (Windows Form) in Managed C++ that accepts an array of image filenames and will display them sequentially. All images will be the same size. I got it to work, but I know something is not right because of the way I am using Application::DoEvents() (ref: http://www.codinghorror.com/blog/archives/000159.html and http://www.codinghorror.com/blog/archives/000370.html ), along with the fact that I get a crash when I try...
4
2010
by: TomA | last post by:
Hi All, I have a picturebox on a form containing the photo of a person. As you advance through the records, the photo updates. Rather than storing the images in an inefficient blob field in a table, I have the separate images stored in an image directory with primary key as the filename (3476.jpg). If the image exists, I display the image. All this works fine. I have a buttons that allow for the insertion and deletion of photos. ...
4
10161
by: =?Utf-8?B?U3BlZWR5?= | last post by:
Hi there, I am currently writing an application where one inspects images and annotates certain features. Thus, one has to zoom in (4x) and pan around. The features are marked with little red rectangles.The images are 2048x2048 pixels. It seems that I can find no efficient way to implement both zooming and panning. At present I have a panel with autoscroll set to true inside which there is
1
2439
by: san123456789 | last post by:
Hi, Im using a MS SQL server to store images... Im creating a windows form application using C#. I need to store and retrieve images from the database. This is my code to store images: pictureBox.Image = new System.Drawing.Bitmap(this.openFileDialog.FileName);
1
2079
by: Amnu | last post by:
Hi there, I've been told to write a custom control using C#.NET ( 2.0 ). This control should be able to display images and give access to zoom functionality. I've visited numerous How-To pages and the main stream approach appears to be a panel/groupBox containing a pictureBox, resizing that pictureBox and using the PictureBoxSizeMode.StretchImage property. I don't want that. What I want is some "real" zoom effect. So I continued my search...
5
23918
krungkrung
by: krungkrung | last post by:
hi again to everyone! I made a simple program(for my VB.Net practice). The program loads an image file to a picturebox upon clicking a button. after loading the image file i have another button to delete the loaded image file from the directory. But I have a problem deleting the image file used by the picturebox even if I set the "PictureBox1.Image = Nothing" before deletion takes place. The error says, "The process cannot access the file...
0
9619
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9454
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
10260
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...
1
10038
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9910
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
8933
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...
0
5354
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...
1
4007
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3609
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.