473,324 Members | 2,002 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

Question about PictureBox.Dispose

I'm developing an application for my customer to log info about photos/images
he has done. Each record contains the file name of the image and displays
the image based on that file name in a PictureBox control.

The app works well until trying to go to another record from a record where
there is not a file name present. If no file name, a label displays that an
image is needed. But if you try to go to another record with an image, that
records' image does not display.

I use the Dispose method if the current record does not have an image or
else the previous record's image will display. But it appears that the
Dispose method keeps the image from displaying for any record that you go to
next.

I tried setting the PictureBox to Nothing, instead of using Dispose, but
that gave me a Null error when trying to store an image to it.

Here is a snippet of my code:
If Me.txtImageFileName IsNot DBNull.Value And
Me.txtImageFileName.Text <"" Then
Me.lblImageNeeded.Visible = False
Me.PhotoOrImage.Image =
Image.FromFile(Me.txtImageFileName.Text)
Else
Me.PhotoOrImage.Dispose()
Me.lblImageNeeded.Visible = True
End If

Is there some other method to use other than Dispose?

Thanks in advance.

Nov 2 '07 #1
2 1893
Once you call Dispose on an object, you can no longer use that object.

Did you try setting the Image property to Nothing?

You could set the image object's Visible property to False when you
don't want to show a picture. Without knowing what type of object you
are using to show the image I can't think of anything else to do.

On Fri, 2 Nov 2007 13:33:30 -0700, EManning
<EM******@discussions.microsoft.comwrote:
>I'm developing an application for my customer to log info about photos/images
he has done. Each record contains the file name of the image and displays
the image based on that file name in a PictureBox control.

The app works well until trying to go to another record from a record where
there is not a file name present. If no file name, a label displays that an
image is needed. But if you try to go to another record with an image, that
records' image does not display.

I use the Dispose method if the current record does not have an image or
else the previous record's image will display. But it appears that the
Dispose method keeps the image from displaying for any record that you go to
next.

I tried setting the PictureBox to Nothing, instead of using Dispose, but
that gave me a Null error when trying to store an image to it.

Here is a snippet of my code:
If Me.txtImageFileName IsNot DBNull.Value And
Me.txtImageFileName.Text <"" Then
Me.lblImageNeeded.Visible = False
Me.PhotoOrImage.Image =
Image.FromFile(Me.txtImageFileName.Text)
Else
Me.PhotoOrImage.Dispose()
Me.lblImageNeeded.Visible = True
End If

Is there some other method to use other than Dispose?

Thanks in advance.
Nov 2 '07 #2
Setting the visible property seems to work fine. Thanks for your help.

"Jack Jackson" wrote:
Once you call Dispose on an object, you can no longer use that object.

Did you try setting the Image property to Nothing?

You could set the image object's Visible property to False when you
don't want to show a picture. Without knowing what type of object you
are using to show the image I can't think of anything else to do.

On Fri, 2 Nov 2007 13:33:30 -0700, EManning
<EM******@discussions.microsoft.comwrote:
I'm developing an application for my customer to log info about photos/images
he has done. Each record contains the file name of the image and displays
the image based on that file name in a PictureBox control.

The app works well until trying to go to another record from a record where
there is not a file name present. If no file name, a label displays that an
image is needed. But if you try to go to another record with an image, that
records' image does not display.

I use the Dispose method if the current record does not have an image or
else the previous record's image will display. But it appears that the
Dispose method keeps the image from displaying for any record that you go to
next.

I tried setting the PictureBox to Nothing, instead of using Dispose, but
that gave me a Null error when trying to store an image to it.

Here is a snippet of my code:
If Me.txtImageFileName IsNot DBNull.Value And
Me.txtImageFileName.Text <"" Then
Me.lblImageNeeded.Visible = False
Me.PhotoOrImage.Image =
Image.FromFile(Me.txtImageFileName.Text)
Else
Me.PhotoOrImage.Dispose()
Me.lblImageNeeded.Visible = True
End If

Is there some other method to use other than Dispose?

Thanks in advance.
Nov 5 '07 #3

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

Similar topics

2
by: Sean | last post by:
Hello all, I have an application that is using some picture box controls that are being used to preview jpg files. The jpg files are created on the fly and will be overwritten when needed. The...
2
by: Sharon | last post by:
I encountered a strange behavior when doing ‘new Bitmap’: The following code works fine and the given bitmap file is shown on the PictureBox (the m_DrawArea) in the correct bitmap sizes: ...
2
by: David Ricker | last post by:
I have created a PictureBox control which can have it's Image property directly bound to an image field in a database. This works perfectly for showing the images that are in the database. When I...
2
by: active | last post by:
Problem: The PictureBox display appears to have the image cut off. I.e., the image bottom does not display although the PictureBox has room for it. It occurred to me that what was displayed was...
3
by: active | last post by:
I draw text in a bitmap and then draw the bitmap on a picturebox and get text that is not all displayed the same. Note the different text style in the (40, 100) area. Got any insight into...
0
by: akh | last post by:
I want to use de Drag and Drop ´s event to move a picture box from a form and within a Picture Box. But I have behaviour if the MyPBox As PictureBox as the Globale varible or not Thanks for...
9
by: rut | last post by:
If I have a picturebox with a background image and I want to 1. Display text atop of the background and 2. Have transistions between text; ie, when the text changes, the screen can fade out/in...
9
by: davetelling | last post by:
I am not a programmer, I'm an engineer trying to make an interface to a product I'm designing. I have used C# to make a form that interrogates the unit via the serial port and receives the data. I...
4
by: gerardianlewis | last post by:
Any help appreciated. (VB.NET under XP and Vista, SP1 installed) My code, inherited from a VB6 version of an app that ran under W98, loads an image from a file into a PictureBox. The user may...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.