0

1〜6の数字をスクロールして、ランダムな数字に到達するタイマーがあります。問題は、同じことをする必要があるピクチャーボックスがあることです。私はサイコロの画像を持っていますが、以下のコードに一致するようにすべてのサイコロの画像をスクロールする方法がわかりません。両方を実行して、一致させるようにします。私は完全に立ち往生しています!

 Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        m = m + 10
        If m < 1000 Then
            n = Int(1 + Rnd() * 6)
            LblDice.Text = n

        Else
            Timer1.Enabled = False
            m = 0
        End If


    End Sub

    Private Sub RollDiceBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RollDiceBtn.Click
        Timer1.Enabled = True

        DisplayDie(die1PictureBox)

    End Sub
4

1 に答える 1

0

これが最善の解決策かどうかはわかりませんが、「ローリング画像」を必要な順序で imageList に入れることができます。次に、TimerTick 内のカウンターを使用して、imageList 内の次の画像を表示できます。

メールで次のコードを見つけました。

 Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick
    If ticks < 11 Then 'I got 11 images
        PictureBox1.BackgroundImage = ImageList1.Images(ticks)
        ticks += 1
    Else
        ticks = 0
        PictureBox1.BackgroundImage = ImageList1.Images(ticks)
        ticks += 1
    End If
End Sub

コメントの後: フォームに imageList を追加します。imageList(サイズ、深さ) で画像のプロパティを設定します。imageList では、サイコロの 6 つの画像を追加します。次に、次のコードを追加します。

 Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick
    m = m + 1 
    If m < 10 Then 'How many ticks (rolls) do you like
        n = Int(1 + Rnd() * 6)
        Label1.Text = n 'The labels is showing your random number (dice number)
        PictureBox1.Image = ImageList1.Images(n - 1) 'This is showing the dice image to the pictureBox:the same as the number
        'I use n-1 because imageList is zero based.
        'Important: my images are in the right order 1,2,3,4,5,6 in the imageList
    Else
        Timer1.Enabled = False
        m = 0
    End If
End Sub

Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
    Timer1.Enabled = True
End Sub
于 2013-02-27T08:01:02.033 に答える