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

Two clicks for a button

100+
P: 759
Hello !
I try to switch from VB6 to VB.NET.
For now I use 2008 Express Edition.

Look at this code, please:
Expand|Select|Wrap|Line Numbers
  1. Public Class frmMovieBuild
  2.     Dim StopMovie As Boolean
  3.  
  4.     Private Sub cmdPlayMovie_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdPlayMovie.Click
  5.         StopMovie = False
  6.         Dim i As Long, jpg As String
  7.         i = 0
  8.         Do While i <= lstMainMovie.Items.Count - 1
  9.                 System.Windows.Forms.Application.DoEvents()
  10.             jpg = lstMainMovie.Items.Item(i).ToString
  11.                 System.Windows.Forms.Application.DoEvents()
  12.             pic_MoviePreview.Image = Image.FromFile(jpg)
  13.                 System.Windows.Forms.Application.DoEvents()
  14.             If StopMovie Then
  15.                 MsgBox("Stopped by user")
  16.                 Exit Do
  17.             End If
  18.             i = i + StepFrames.Value 'Here I use a slider control
  19.         Loop
  20.     End Sub
  21.  
  22.     Private Sub cmdStopMovie_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdStopMovie.Click
  23.         StopMovie = True
  24.     End Sub
  25.  
  26. End Class
  27.  
When I run the form, first I click the cmdPlayMovie button.
Then I try to exit by clicking the cmdStopMovie button (in order to set the StopMovie variable to TRUE).
And here is the problem:
At the first click, nothing happen. The cmdStopMovie button seems to take the focus.
Then, at the second click, the "Stopped by user" message appear.

For my project is strongly necessary to stop the movie at a certain frame.
That means that cmdStopMovie button must react at the first click.

Is there a bug or there are some settings to do ?

Hope I have explained well my problem.

More one question (If necessary I'll start a new thread for this).
The WHILE clause seems to have no effect in Do-Loop cycle. So this cycle run for ever (except if I click the cmdStopMovie button).
Can someone understand (and explain) WHY ?

Thank you !
Nov 11 '12 #1

✓ answered by IronRazer

I have run into the problem you where having in an old program of mine and here is the fix i used for it. I changed a little of the code but it should work fine.

First add a timer. Then use this code :
Expand|Select|Wrap|Line Numbers
  1.     Private Sub cmdPlayMovie_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdPlayMovie.Click
  2.         Timer1.Start()
  3.     End Sub
  4.  
  5.     Private Sub cmdStopMovie_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdStopMovie.Click
  6.         StopMovie = True
  7.     End Sub
  8.  
  9.     Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
  10.         Timer1.Stop()
  11.         StopMovie = False
  12.         Dim i As Long
  13.         i = 0
  14.         While (i <= frames And Not StopMovie)
  15.             System.Windows.Forms.Application.DoEvents()
  16.             jpg = lstMainMovie.Items.Item(i).ToString
  17.             System.Windows.Forms.Application.DoEvents()
  18.             pic_MoviePreview.Image = Image.FromFile(jpg)
  19.             System.Windows.Forms.Application.DoEvents()
  20.             i += StepFrames 'Here I use a slider control
  21.         End While
  22.         If StopMovie Then
  23.             MsgBox("Stopped by user")
  24.         End If
  25.     End Sub
  26.  

Share this Question
Share on Google+
1 Reply


IronRazer
P: 83
I have run into the problem you where having in an old program of mine and here is the fix i used for it. I changed a little of the code but it should work fine.

First add a timer. Then use this code :
Expand|Select|Wrap|Line Numbers
  1.     Private Sub cmdPlayMovie_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdPlayMovie.Click
  2.         Timer1.Start()
  3.     End Sub
  4.  
  5.     Private Sub cmdStopMovie_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdStopMovie.Click
  6.         StopMovie = True
  7.     End Sub
  8.  
  9.     Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
  10.         Timer1.Stop()
  11.         StopMovie = False
  12.         Dim i As Long
  13.         i = 0
  14.         While (i <= frames And Not StopMovie)
  15.             System.Windows.Forms.Application.DoEvents()
  16.             jpg = lstMainMovie.Items.Item(i).ToString
  17.             System.Windows.Forms.Application.DoEvents()
  18.             pic_MoviePreview.Image = Image.FromFile(jpg)
  19.             System.Windows.Forms.Application.DoEvents()
  20.             i += StepFrames 'Here I use a slider control
  21.         End While
  22.         If StopMovie Then
  23.             MsgBox("Stopped by user")
  24.         End If
  25.     End Sub
  26.  
Jan 19 '13 #2

Post your reply

Sign in to post your reply or Sign up for a free account.