VB.Net >> Picturebox refresh problems

by John Dann » Fri, 30 Jan 2009 20:07:42 GMT

I have a remote network application that is placing a frequently
updated copy of an image file on to a network drive every few seconds
and I'm trying to write a little utility to view and automatically
refresh the image on a local PC. The refresh is meant to happen in 2
stages - a file copy and an image refresh - which are both running in
a timer loop:

Timer1_Tick(etc...)
File.Copy(RemoteImageFile, LocalImageFile, True))
Picturebox1.Image = Image.FromFile(LocalImageFile)
Picturebox1.Refresh
End Sub

This runs OK for the first timer event but at the second tick then
there's an IOException at the File.Copy line, apparently because the
file copy cannot complete and then presumably because the picturebox
still has the image file open.

Is there some way of closing the picturebox's access to the file (if
indeed that's what's causing the problem)?

VB.Net >> Picturebox refresh problems

by Armin Zingler » Fri, 30 Jan 2009 20:33:00 GMT



Untested:

Timer1_Tick(etc...)
dim img as image

img = picturebox1.image

if img isnot nothing then
picturebox1.image = nothing
img.dispose
end if

File.Copy(RemoteImageFile, LocalImageFile, True))

Picturebox1.Image = Image.FromFile(LocalImageFile)
Picturebox1.Refresh
End Sub


Does this work?


Armin

VB.Net >> Picturebox refresh problems

by Lloyd Sheen » Sat, 31 Jan 2009 00:16:12 GMT


For some reason the code you are using retains a lock on the file. I use
the following code:

Using stream As Stream = New FileStream(fileName, FileMode.Open,
FileAccess.Read)
pb.Image = Image.FromStream(stream)
End Using

This will not hold a lock on the file. Go figure.

LS

VB.Net >> Picturebox refresh problems

by Cor Ligthert[MVP] » Sat, 31 Jan 2009 02:16:48 GMT

Hi John,

I am curious, why do you use a timer and not simple a file watcher?

In combination with the code from Lloyd.

http://msdn.microsoft.com/en-us/library/system.io.filesystemwatcher (VS.80).aspx

Cor

VB.Net >> Picturebox refresh problems

by John Dann » Sat, 31 Jan 2009 02:38:28 GMT

Thanks everyone - I'll give those solutions a go.

Cor, the reason for using a timer was a combination of ignorance and
safety. I just wasn't sure how well FSW works when monitoring a file
across a network, or if it works well (as it probably does) how much
of a load/traffic it might place across the network. This watching
event would need to happen every 2-3 seconds continuously 24/7 and I'm
also anxious not to interfere in any way with the completely separate
process that generates the source file. So it was safety first really
even if it's a less elegant solution..

On Fri, 30 Jan 2009 19:16:48 +0100, "Cor Ligthert[MVP]"

Similar Threads

1. Panel refresh with pictureboxes very slow

2. How to don't refresh Control of PictureBox Having?

uses statement:


System.Windows.Forms.PictureBox pictureBox1;
System.Windows.Forms.Panel panel1;

   pictureBox1 = new System.Windows.Forms.PictureBox();
   panel1 = new System.Windows.Forms.Panel();

 //
    // panel1
    //
    panel1.BackColor = System.Drawing.Color.Transparent;
   panel1.Location = new System.Drawing.Point(40, 88);
  //
    // pictureBox1
    //
   pictureBox1.Image =
((System.Drawing.Bitmap)(resources.GetObject("pictureBox1.Image")));
    pictureBox1.Location = new System.Drawing.Point(16, 16);
    pictureBox1.Size = new System.Drawing.Size(248, 224);
    pictureBox1.SizeMode =
System.Windows.Forms.PictureBoxSizeMode.StretchImage;

   pictureBox1.Controls.Add(panel1);

PictureBox.Image is a GIF Animate,so should refresh panel1 in run ,how to
don't.


3. Problem with refresh button breaking automatic refresh - Asp.Net

4. .NET PictureBox vs VB6 PictureBox

I noticed that the .NET picturebox is a lot more memory intensive.  I created an app ( VB.NET ) with a picturebox and loaded a test.bmp ( a 75mb bitmap image)  when I run the app, the image loads quickly, but if I click on my form and drag it around the screen, it is very very choppy.  I look at task manager and see that my memory keeps going up as I move my form

I do the same test in VB6 using the VB6 picture box, and there is 0 delay when i move my form around the screen and my memory is stable.  How do I get the same results in VB.NET using the picturebox ??

5. Copy Image in picturebox to another picturebox - VB.Net

6. Keep PictureBox within PictureBox when Dragging

I have seen this successfully done in MFC, but can't get it to work in VB6
Classic.  (Also want to get the idea working in VB.NET, but no flames
please.  Yes, we do know where the DotNet NG's are.)

The concept is to have a PictureBox1, and then  PictureBox2 lives -  is
inserted, inside PictureBox1.  On LeftMouseButtonDown when dragging
PictureBox2 around inside PictureBox1, I don't want PictureBox 2's top,
bottom, right or left side to excceed the top, bottom, right or left of
PictureBox1.(Inotherwords, I always want PictureBox2  to >always< stay,
100%,  >inside< PictureBox1)

Dragging is stopped either with releasing the mousebutton or when the cursor
exceeds the bounds of PictureBox1.

I have dragging stopping OK using GetCursorPos and POINTAPI through the API.
when the cursor exceeds the top, bottom, right or left of PictureBox1, but
the PictureBox2 bounds go outside the bounds of PictureBox1.

Probably, for some doorknob simple reason, I can't figure out how to do it
right.

The above is dumbed down from project using LeadTools OCX for TWAIN graphics
acquisition.  PictureBox1 = Lead1.  PictureBox2 = Lead2, which will be
cropping area of Lead1.

Have strip-mined Google, but can't seem to find anything appropriate.

Anyone been there - done this or have any ideas?  Sample gratefully
appreciated.

Pete


7. How to delete a Picturebox by draging it to another picturebox or control

8. How can I center a PictureBox within another PictureBox

I have a PictureBoxB within another PictureBoxA.
I write :
PictureBoxB.move (PictureBoxA.Width - PictureBoxB.Width) / 2, _
                       (PictureBoxA.Height - PictureBoxB.Height) / 2

but I see that the PictureBoxB dont centered .
Why this ?