我的游戏说明:
当你开始游戏时,你有几秒钟记住网格的排列。通过这种安排,我的意思是每个网格是两种颜色中的一种。时间结束后,所有网格都设置为“关闭”颜色。玩家必须点击网格来切换它们并将它们放入正确的颜色分配中。
好的,所以这是我正在开发的游戏的一部分。我不想使用纯色,我想使用背景图像,但我不知道如何编辑代码来做到这一点。欢迎任何帮助。
Dim GridOn As Color = Color.LightBlue
Dim GridOff As Color = Color.DarkBlue
Dim MaxTime As Integer = 40
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
For Each pic As Control In Me.Controls 'For every picture in form1's controls...
If TypeOf pic Is PictureBox Then 'Then, only picks the pictureboxes, not the buttons, labels, etc.
AddHandler pic.Click, AddressOf PictureBoxClick 'For each picturebox (grid), add an event handler (PictureBoxClick) to avoid
End If 'typing 16 of them ourselves
Next
End Sub
Private Sub PictureBoxClick(ByVal sender As System.Object, ByVal e As System.EventArgs)
If AllowEdit = True Then
Dim ctrl As PictureBox = DirectCast(sender, Control)
If ctrl.BackColor = GridOn Then
ctrl.BackColor = GridOff 'Set the backcolor to either GridOn or GridOff
Else : ctrl.BackColor = GridOn
End If
Else
'Do not allow the user to change the colors
End If
End Sub
答案 0 :(得分:1)
完全回答你的问题......
picturebox.imageLoaction ="目录"而不是picturebox.backcolor
对于考虑尝试,
一种解决方法是将整数常量或字符串常量存储到图片框的Tag字段中,以识别放置在图片框中的图像。 e.g。
pbo1.Tag = "Ice Cream"
' or
pbo1.Tag = IMAGE.icecream
' where
Enum IMAGE
ICE CREAM
CHERRY
' etc....
End Enum