Random 随机骰子图片
在Picturebox中将骰子的6个面随机化的代码是什么。如果我单击滚动按钮,6个图片框将随机排列。使用计时器。计时器中的代码是什么。请帮忙。我是一个初学者,我不知道如何随机设置图片框。谢谢。在进入代码之前,您需要执行一些步骤,我将在图片中向您展示这些步骤,以便您更容易理解 1.将骰子的所有面作为图像添加到“资源”选项卡中。 2.设计:Random 随机骰子图片,random,timer,picturebox,vb.net-2010,Random,Timer,Picturebox,Vb.net 2010,在Picturebox中将骰子的6个面随机化的代码是什么。如果我单击滚动按钮,6个图片框将随机排列。使用计时器。计时器中的代码是什么。请帮忙。我是一个初学者,我不知道如何随机设置图片框。谢谢。在进入代码之前,您需要执行一些步骤,我将在图片中向您展示这些步骤,以便您更容易理解 1.将骰子的所有面作为图像添加到“资源”选项卡中。 2.设计: Public Class Form1 Dim Rnd As New Random Dim FaceX, X As Integer
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
在您的设计中添加一个计时器(计时器1)、一个按钮(按钮1)、一个picturebox(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
在开始编写代码之前,您需要执行一些步骤,我将在图片中向您展示这些步骤,以便您更容易理解 1.将骰子的所有面作为图像添加到“资源”选项卡中。 2.设计:
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
在您的设计中添加一个计时器(计时器1)、一个按钮(按钮1)、一个picturebox(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