【发布时间】:2017-03-21 17:20:42
【问题描述】:
我的游戏描述:
当您开始游戏时,您有几秒钟的时间来记住网格的排列。通过排列,我的意思是每个网格都是两种颜色中的一种。时间到后,所有网格都设置为“关闭”颜色。玩家必须点击网格来切换它们并将它们按照之前看到的正确颜色分配。
好的,这是我正在开发的游戏的一部分。我不想使用纯色,而是使用背景图像,但我不知道如何编辑代码来做到这一点。欢迎任何帮助。
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
【问题讨论】:
-
PictureBox 有一个 Image 属性。是这个问题吗?
-
picturebox.imageLoaction = "目录" 而不是 picturebox.backcolor
-
谢谢。但是我仍然对如何进行比较感到困惑, ctrl = gridOn ,将图像与图像进行比较,我们不能这样做吗?
标签: vb.net