首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >随机骰子图片

随机骰子图片
EN

Stack Overflow用户
提问于 2017-03-03 02:42:01
回答 1查看 100关注 0票数 1

图片盒中的6个骰子的随机化代码是什么?如果我点击滚动按钮,6个图片框将是随机的。用计时器。计时器中的代码是什么。请帮帮忙。我是一个初学者,我不知道如何随机的图片盒。谢谢。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-03-03 06:13:30

在进入代码之前,您需要执行一些步骤,我将在图片中向您展示这些步骤,这样对您来说就更容易了。

1.将骰子的所有面作为图像添加到“参考资料”选项卡中.

2.设计:

在您的设计中添加一个定时器(Timer1)、一个按钮(Button1)、一个图片框(Picturebox1)。

3.代码:

代码语言:javascript
运行
复制
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
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42569688

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档