如何使图片框随机出现在屏幕上

问题描述

我正在vb.net中编写一个僵尸游戏,需要使僵尸(我在图片框和数组中放置的僵尸,共有13个)随机出现,每杀死1个僵尸就可能出现两个。我怎样才能在代码中做到这一点?我是编码新手,即使经过大量搜索也无法弄清楚。

解决方法

我想我了解您要做什么。

您将要在代码中构造一个图片框,然后定义您希望其在表单上“生成”的位置。

您可以从这样的内容开始,如果您一次要拥有多个僵尸,则需要列出它们的列表或对其进行唯一命名,以便以后参考(移动它们) / despawning / etc)

    Private Sub Button1_Click(sender As Object,e As EventArgs) Handles Button1.Click
    Dim zombie As New PictureBox
    With zombie
        zombie.Width = 100 'or the size you need
        zombie.Height = 100 ' same thing
        zombie.Top = 20 'or where you need it could be a random
        zombie.Left = 20 'same as top
        zombie.ImageLocation = "C:\mydocuments\zombie.png" 'change this to the location of your zombie image. if you're storing it in a resource you can call it here
    End With
    Me.Controls.Add(zombie)
End Sub

这至少应该让您入门

编辑:我错过了您说的要为僵尸配备阵列的部分,但是您也可以对图片框进行阵列

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...