Two clicks for a button

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Mihail
    Contributor
    • Apr 2011
    • 759

    Two clicks for a button

    Hello !
    I try to switch from VB6 to VB.NET.
    For now I use 2008 Express Edition.

    Look at this code, please:
    Code:
    Public Class frmMovieBuild
        Dim StopMovie As Boolean
    
        Private Sub cmdPlayMovie_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdPlayMovie.Click
            StopMovie = False
            Dim i As Long, jpg As String
            i = 0
            Do While i <= lstMainMovie.Items.Count - 1
                    System.Windows.Forms.Application.DoEvents()
                jpg = lstMainMovie.Items.Item(i).ToString
                    System.Windows.Forms.Application.DoEvents()
                pic_MoviePreview.Image = Image.FromFile(jpg)
                    System.Windows.Forms.Application.DoEvents()
                If StopMovie Then
                    MsgBox("Stopped by user")
                    Exit Do
                End If
                i = i + StepFrames.Value 'Here I use a slider control
            Loop
        End Sub
    
        Private Sub cmdStopMovie_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdStopMovie.Click
            StopMovie = True
        End Sub
    
    End Class
    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 !
  • IronRazer
    New Member
    • Jan 2013
    • 83

    #2
    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 :
    Code:
        Private Sub cmdPlayMovie_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdPlayMovie.Click
            Timer1.Start()
        End Sub
    
        Private Sub cmdStopMovie_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdStopMovie.Click
            StopMovie = True
        End Sub
    
        Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
            Timer1.Stop()
            StopMovie = False
            Dim i As Long
            i = 0
            While (i <= frames And Not StopMovie)
                System.Windows.Forms.Application.DoEvents()
                jpg = lstMainMovie.Items.Item(i).ToString
                System.Windows.Forms.Application.DoEvents()
                pic_MoviePreview.Image = Image.FromFile(jpg)
                System.Windows.Forms.Application.DoEvents()
                i += StepFrames 'Here I use a slider control
            End While
            If StopMovie Then
                MsgBox("Stopped by user")
            End If
        End Sub

    Comment

    Working...