1
在Picturebox中对骰子的6个面进行随机化的代码是什么?如果我点击滚动按钮,6个图片框将随机化。使用计时器。定时器中的代码是什么?请帮忙。我是一个初学者,我不知道如何随机的图片框。谢谢。随机骰子图片
在Picturebox中对骰子的6个面进行随机化的代码是什么?如果我点击滚动按钮,6个图片框将随机化。使用计时器。定时器中的代码是什么?请帮忙。我是一个初学者,我不知道如何随机的图片框。谢谢。随机骰子图片
在进入代码之前,您需要执行一些步骤,并且我会在图片中向您显示这些步骤,以便您更轻松地进行操作。
1.将骰子的所有面添加为“资源”选项卡中的图像。
2.设计:
添加到您设计的定时器(定时器),一个按钮(按钮1),一个图片(Picturebox1)。
3,代码:
Public Class Form1
Dim Rnd As New Random
Dim FaceX, X As Integer
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Timer1.Start()
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Timer1.Stop()
If X = 10 Then 'Note : 10 is the number of shuffling the images.
X = 0
Else
FaceX = Rnd.Next(1, 7)
If FaceX = 1 Then
PictureBox1.Image = My.Resources.DiceFace_1 'Note : replace [DiceFace_1] with the name of the image of the face1 of the dice that you added it in the Resources, and do that to all the coming commands....
ElseIf FaceX = 2 Then
PictureBox1.Image = My.Resources.DiceFace_2
ElseIf FaceX = 3 Then
PictureBox1.Image = My.Resources.DiceFace_3
ElseIf FaceX = 4 Then
PictureBox1.Image = My.Resources.DiceFace_4
ElseIf FaceX = 5 Then
PictureBox1.Image = My.Resources.DiceFace_5
ElseIf FaceX = 6 Then
PictureBox1.Image = My.Resources.DiceFace_6
End If
X += 1
Timer1.Start()
End If
End Sub
End Class
谢谢主席先生。我懂了。它的工作。 –
不客气:) –