1

一連の 7 つの画像ボックス (命令、黒の背景、画像、黒の背景など) を表示するプログラムを作成しようとしています。最初のピクチャーボックス。人は、少なくとも最初の 4 つの画像ボックス、おそらく 7 つ目の画像ボックスまではハンドルを握り続けなければなりません。ピクチャボックスが画面いっぱいに表示されます。ボックスからボックスへの遷移は、winmm.dll の timeGetTime によって管理されます。プログラムのシーケンス部分は、非常にうまく機能します。

ただし、2つの問題があります

  1. 中央のマウスアップが 5 番目のピクチャボックスの前に発生した場合、この picBoxes の実行を停止して最初の picBox に戻ることができる必要があります。
  2. 5 番目、6 番目、または 7 番目のボックスで発生したマウス アップ イベントの時間を記録する必要があります。

次に、マウスの左ボタンまたは右ボタンを押すと、問題なく動作します。主な問題の 1 つは、mouseup イベントが機能していないように見えますが、プログラムの後半で、人が左または右のボタンに指を置いて、もう一度クリックしたときに機能します。

前のサブルーチンにあるシーケンスの後、シーケンス A (ピクボックス 1 ~ 4) とシーケンス B (ピクボックス 5 ~ 7) に分割しました。私は置きました:

Private Property sequenceA As Boolean
Private Property sequenceB As Boolean

Private Sub picBox2_mouseup(ByVal sender As Object, ByVal e As MouseEventArgs) Handles picBox2.MouseUp
   If MouseButtons.Middle Then
       If sequenceA = True Then
           picBox1.Visible = True
           sequenceB = False
           sequenceA = False
       End If
   End If
End Sub

私は何日も努力してきました!そして、上記のコードは、それが機能した場合、マウスが picBox2 で上がったかどうかだけを教えてくれますが、picbox 2-4 については知る必要があります。

4

2 に答える 2

1

私のコメントに基づいて、シングルPictureBoxを使用してすべての画像を表示するコードを作成しました。これにより、処理が可能にMouseUpなりMouseDownます。

Public Class Form1

    Private currentImageIndex As Integer
    Private images As List(Of Bitmap)
    Private loopTimer As Threading.Timer
    Private timeForEachImage As Long = 500 ' ms
    Private stopTime As DateTime

    Private Sub PictureBox1_MouseUp(sender As Object, e As MouseEventArgs) Handles PictureBox1.MouseUp
        If e.Button = Windows.Forms.MouseButtons.Middle Then
            stopLoop()
            Select Case currentImageIndex
                Case 0 To 3 ' stopped before the 5th
                    changePictureIndex(0)
                Case 4, 5, 6 ' on or after the 5th
                    stopTime = DateTime.Now
            End Select
        End If
    End Sub

    Private Sub PictureBox1_MouseDown(sender As Object, e As MouseEventArgs) Handles PictureBox1.MouseDown
        If e.Button = Windows.Forms.MouseButtons.Middle Then startLoop()
    End Sub

    Private Sub startLoop()
        stopLoop()
        currentImageIndex = 0
        loopTimer.Change(0, timeForEachImage)
    End Sub

    Private Sub stopLoop()
        loopTimer.Change(Threading.Timeout.Infinite, Threading.Timeout.Infinite)
    End Sub

    Private Sub imageTimerCallback()
        currentImageIndex = Math.Min((currentImageIndex + 1), 7)
        If currentImageIndex < 7 Then changePictureIndex(currentImageIndex)
    End Sub

    Private Sub changePictureIndex(ByVal index As Integer)
        If PictureBox1.InvokeRequired Then
            PictureBox1.Invoke(New Action(Of Integer)(AddressOf changePictureIndex), index)
        Else
            PictureBox1.Image = images(index)
        End If
    End Sub

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        images = New List(Of Bitmap)
        images.Add(New Bitmap("C:\...\img1.png")) ' load all your images in order
        images.Add(New Bitmap("C:\...\img2.jpg")) ' etc.
        loopTimer = New Threading.Timer(AddressOf imageTimerCallback)
    End Sub

End Class
于 2014-02-17T23:06:33.473 に答える