943,028 Members | Top Members by Rank

Ad:
  • VB.NET Discussion Thread
  • Unsolved
  • Views: 1696
  • VB.NET RSS
Oct 13th, 2008
0

How to stop a loop displaying photos?

Expand Post »
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

vbnet Syntax (Toggle Plain Text)
  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
Reputation Points: 10
Solved Threads: 0
Light Poster
Sheryl99 is offline Offline
27 posts
since Sep 2008
Oct 13th, 2008
0

Re: How to stop a loop displaying photos?

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

VB Syntax (Toggle Plain Text)
  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.
Reputation Points: 44
Solved Threads: 101
Posting Pro
selvaganapathy is offline Offline
547 posts
since Feb 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in VB.NET Forum Timeline: embeding excel spreadsheet into stand alone Vb.net program
Next Thread in VB.NET Forum Timeline: How Could I Do Nested Datagridview in vb.net





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC