图片盒中的6个骰子的随机化代码是什么?如果我点击滚动按钮,6个图片框将是随机的。用计时器。计时器中的代码是什么。请帮帮忙。我是一个初学者,我不知道如何随机的图片盒。谢谢。
发布于 2017-03-03 06:13:30
在进入代码之前,您需要执行一些步骤,我将在图片中向您展示这些步骤,这样对您来说就更容易了。
1.将骰子的所有面作为图像添加到“参考资料”选项卡中.
2.设计:
在您的设计中添加一个定时器(Timer1)、一个按钮(Button1)、一个图片框(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
https://stackoverflow.com/questions/42569688
复制相似问题