How to stop a loop displaying photos?

Please support our VB.NET advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Sep 2008
Posts: 27
Reputation: Sheryl99 is an unknown quantity at this point 
Solved Threads: 0
Sheryl99 Sheryl99 is offline Offline
Light Poster

How to stop a loop displaying photos?

 
0
  #1
Oct 13th, 2008
Hello.

I am writing an application that displays photos. I need to be able to stop the SlideShow when the user presses the "Stop" button. Right now, what's happening when the Stop button is pressed, is a public variable, bStop, is set to True. It works sort-of, and it also takes a long time. There must be a better way. Any ideas?

Thanks

  1. Private Sub SlideShow()
  2. Dim x As Integer = 0
  3. With cboFileNames
  4. For x = 0 To (.Items.Count) - 1
  5. If bStop Then Exit For
  6. PictureBox1.Image = Image.FromFile(.Items(x).ToString)
  7. My.Application.DoEvents()
  8. Threading.Thread.Sleep(3000)
  9. Next
  10. End With
  11. End Sub
Last edited by cscgal; Oct 13th, 2008 at 12:24 pm. Reason: Fixed code tag
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 526
Reputation: selvaganapathy is an unknown quantity at this point 
Solved Threads: 89
selvaganapathy's Avatar
selvaganapathy selvaganapathy is offline Offline
Posting Pro

Re: How to stop a loop displaying photos?

 
0
  #2
Oct 13th, 2008
Hi,
Use Timer control instead of Thread.Sleep (). Because ur application will freeze for the given milliseconds.

if you use timer control, you can disable the timer when stop button is clicked.

To use timer, change the Following

> Use X as Global variable
> Draw a Timer Control and Set Enabled Property to True and Interval property to 3000
> Place the above code into Timer_Tick event

  1. Dim x As Integer = 0
  2.  
  3. Private Sub Timer1_Tick ( ... )
  4. With cboFileNames
  5. 'For x = 0 To (.Items.Count) - 1
  6. 'If bStop Then Exit For
  7. PictureBox1.Image = Image.FromFile(.Items(x).ToString)
  8. My.Application.DoEvents()
  9. 'Threading.Thread.Sleep(3000)
  10. 'Next
  11. x = x + 1
  12. End With
  13. End Sub
  14.  
  15. Private Sub ButtonStop_Click( .. )
  16. Timer1.Enabled = False
  17. End Sub

Note : Also Check the x value whether it is inside upper and lower bound value inside TImer1_Tick Event
Last edited by selvaganapathy; Oct 13th, 2008 at 8:22 am.
Selva
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 985 | Replies: 1
Thread Tools Search this Thread



Tag cloud for VB.NET
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC