By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,825 Members | 1,708 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,825 IT Pros & Developers. It's quick & easy.

Updating PictureBox image every x seconds --how?

P: n/a
I have a routine that updates a PictureBox image every x seconds. I do this
by first loading an array with the path to all of the images. I then
generate a random number to use as the index of the array. A timer is set to
update the PictureBox. This works great the first time through but fails on
all subsequent Timer events. If I simply step through the code it works
fine. If I run it only the first time through does the PictureBox update the
picture. Can someone tell me what I'm doing wrong in getting all subsequent
calls to update the PictureBox to work? My code is:

Within the Timer Tick event....

Dim Photo As Integer

Photo = RandomNumber(ss.Pics.Count)

Dim myImage As Bitmap = New Bitmap(ss.Pics(Photo).FullName, True)

Me.pic1.Image = myImage

As I said, fine the first time through and then each subsequent Tick event
fails to update the PictureBox w/new pic. I have verified that each time
through the path statement is correct. What the heck? It seems simple
enough. What am I doing wrong? I've tried placing a pic1.Dispose call before
and after updating the PictureBox to no avail.

Any insight appreciated!!

JW
Sep 12 '07 #1
Share this Question
Share on Google+
4 Replies


P: n/a
After you change the image try a call to:

Me.pic1.Invalidate

to force the PictureBox to redraw itself.

--
Mike

Mike McIntyre [MVP]
http://www.getdotnetcode.com
"Jerry West" <jw@comcast.netwrote in message
news:13*************@news.supernews.com...
>I have a routine that updates a PictureBox image every x seconds. I do this
by first loading an array with the path to all of the images. I then
generate a random number to use as the index of the array. A timer is set
to update the PictureBox. This works great the first time through but fails
on all subsequent Timer events. If I simply step through the code it works
fine. If I run it only the first time through does the PictureBox update
the picture. Can someone tell me what I'm doing wrong in getting all
subsequent calls to update the PictureBox to work? My code is:

Within the Timer Tick event....

Dim Photo As Integer

Photo = RandomNumber(ss.Pics.Count)

Dim myImage As Bitmap = New Bitmap(ss.Pics(Photo).FullName, True)

Me.pic1.Image = myImage

As I said, fine the first time through and then each subsequent Tick event
fails to update the PictureBox w/new pic. I have verified that each time
through the path statement is correct. What the heck? It seems simple
enough. What am I doing wrong? I've tried placing a pic1.Dispose call
before and after updating the PictureBox to no avail.

Any insight appreciated!!

JW

Sep 13 '07 #2

P: n/a
I'm using VB .NET 2005. The PictureBox control doesn't have an Invalidate
method. It does have a Redraw method and I have tried using that after
setting the image --to no avail.

What could I be missing here? This is very simple to do in VB6.

JW

"Mike McIntyre" <mi****@getdotnetcode.comwrote in message
news:Of**************@TK2MSFTNGP02.phx.gbl...
After you change the image try a call to:

Me.pic1.Invalidate

to force the PictureBox to redraw itself.

--
Mike

Mike McIntyre [MVP]
http://www.getdotnetcode.com
"Jerry West" <jw@comcast.netwrote in message
news:13*************@news.supernews.com...
>>I have a routine that updates a PictureBox image every x seconds. I do
this by first loading an array with the path to all of the images. I then
generate a random number to use as the index of the array. A timer is set
to update the PictureBox. This works great the first time through but
fails on all subsequent Timer events. If I simply step through the code it
works fine. If I run it only the first time through does the PictureBox
update the picture. Can someone tell me what I'm doing wrong in getting
all subsequent calls to update the PictureBox to work? My code is:

Within the Timer Tick event....

Dim Photo As Integer

Photo = RandomNumber(ss.Pics.Count)

Dim myImage As Bitmap = New Bitmap(ss.Pics(Photo).FullName, True)

Me.pic1.Image = myImage

As I said, fine the first time through and then each subsequent Tick
event fails to update the PictureBox w/new pic. I have verified that each
time through the path statement is correct. What the heck? It seems
simple enough. What am I doing wrong? I've tried placing a pic1.Dispose
call before and after updating the PictureBox to no avail.

Any insight appreciated!!

JW


Sep 13 '07 #3

P: n/a
Jerry,

Did you try to disable the timer events at the start of the timer event and
to enable it again at the beginning. Often the event is throwed again even
before the next one is completely handled.
However, I would first try to set the picture number in another way, just to
try it.

Cor

"Jerry West" <jw@comcast.netschreef in bericht
news:13*************@news.supernews.com...
I'm using VB .NET 2005. The PictureBox control doesn't have an Invalidate
method. It does have a Redraw method and I have tried using that after
setting the image --to no avail.

What could I be missing here? This is very simple to do in VB6.

JW

"Mike McIntyre" <mi****@getdotnetcode.comwrote in message
news:Of**************@TK2MSFTNGP02.phx.gbl...
>After you change the image try a call to:

Me.pic1.Invalidate

to force the PictureBox to redraw itself.

--
Mike

Mike McIntyre [MVP]
http://www.getdotnetcode.com
"Jerry West" <jw@comcast.netwrote in message
news:13*************@news.supernews.com...
>>>I have a routine that updates a PictureBox image every x seconds. I do
this by first loading an array with the path to all of the images. I then
generate a random number to use as the index of the array. A timer is set
to update the PictureBox. This works great the first time through but
fails on all subsequent Timer events. If I simply step through the code
it works fine. If I run it only the first time through does the
PictureBox update the picture. Can someone tell me what I'm doing wrong
in getting all subsequent calls to update the PictureBox to work? My code
is:

Within the Timer Tick event....

Dim Photo As Integer

Photo = RandomNumber(ss.Pics.Count)

Dim myImage As Bitmap = New Bitmap(ss.Pics(Photo).FullName, True)

Me.pic1.Image = myImage

As I said, fine the first time through and then each subsequent Tick
event fails to update the PictureBox w/new pic. I have verified that
each time through the path statement is correct. What the heck? It seems
simple enough. What am I doing wrong? I've tried placing a pic1.Dispose
call before and after updating the PictureBox to no avail.

Any insight appreciated!!

JW


Sep 13 '07 #4

P: n/a
Cor,

That was the trick!!! I disabled the Timer and re-enabled per your
suggestion and immediately it worked as I needed. I find this somewhat odd
though, given that I had set the Timer value for >10 seconds which should
have been enough to allow the process to work.

Your the man!

JW

"Cor Ligthert[MVP]" <no************@planet.nlwrote in message
news:2B**********************************@microsof t.com...
Jerry,

Did you try to disable the timer events at the start of the timer event
and to enable it again at the beginning. Often the event is throwed again
even before the next one is completely handled.
However, I would first try to set the picture number in another way, just
to try it.

Cor

"Jerry West" <jw@comcast.netschreef in bericht
news:13*************@news.supernews.com...
>I'm using VB .NET 2005. The PictureBox control doesn't have an Invalidate
method. It does have a Redraw method and I have tried using that after
setting the image --to no avail.

What could I be missing here? This is very simple to do in VB6.

JW

"Mike McIntyre" <mi****@getdotnetcode.comwrote in message
news:Of**************@TK2MSFTNGP02.phx.gbl...
>>After you change the image try a call to:

Me.pic1.Invalidate

to force the PictureBox to redraw itself.

--
Mike

Mike McIntyre [MVP]
http://www.getdotnetcode.com
"Jerry West" <jw@comcast.netwrote in message
news:13*************@news.supernews.com...
I have a routine that updates a PictureBox image every x seconds. I do
this by first loading an array with the path to all of the images. I
then generate a random number to use as the index of the array. A timer
is set to update the PictureBox. This works great the first time through
but fails on all subsequent Timer events. If I simply step through the
code it works fine. If I run it only the first time through does the
PictureBox update the picture. Can someone tell me what I'm doing wrong
in getting all subsequent calls to update the PictureBox to work? My
code is:

Within the Timer Tick event....

Dim Photo As Integer

Photo = RandomNumber(ss.Pics.Count)

Dim myImage As Bitmap = New Bitmap(ss.Pics(Photo).FullName, True)

Me.pic1.Image = myImage

As I said, fine the first time through and then each subsequent Tick
event fails to update the PictureBox w/new pic. I have verified that
each time through the path statement is correct. What the heck? It
seems simple enough. What am I doing wrong? I've tried placing a
pic1.Dispose call before and after updating the PictureBox to no avail.

Any insight appreciated!!

JW


Sep 13 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.