我正在为游戏编写代码,这是一个游戏,你随机看到一个城市的图片,然后你必须在文本框中写下它的名字。
这就是我现在所拥有的:
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Me.BackColor = Color.Yellow
'achtergrond kleur is geel'
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim stad As Integer
Randomize()
stad = Int(Rnd() * 10) + 1
If stad = 1 Then PictureBox1.Image = My.Resources.amsterdam
If stad = 2 Then PictureBox1.Image = My.Resources.berlijn
If stad = 3 Then PictureBox1.Image = My.Resources.moskou
If stad = 4 Then PictureBox1.Image = My.Resources.neworleans
If stad = 5 Then PictureBox1.Image = My.Resources.newyork
If stad = 6 Then PictureBox1.Image = My.Resources.parijs
If stad = 7 Then PictureBox1.Image = My.Resources.rome
If stad = 8 Then PictureBox1.Image = My.Resources.sanfransisco
If stad = 9 Then PictureBox1.Image = My.Resources.shanghai
If stad = 10 Then PictureBox1.Image = My.Resources.tokio
End Sub
Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
Dim name As String
name = TextBox1.Text
If PictureBox1.Image Is My.Resources.amsterdam And name = "amsterdam" Then MsgBox("Dit antwoord is goed voor 1 punt")
If PictureBox1.Image Is My.Resources.berlijn And name = "berlijn" Then MsgBox("Dit antwoord is goed voor 1 punt")
If PictureBox1.Image Is My.Resources.moskou And name = "moskou" Then MsgBox("Dit antwoord is goed voor 1 punt")
If PictureBox1.Image Is My.Resources.neworleans And name = "new orleans" Then MsgBox("Dit antwoord is goed voor 1 punt")
If PictureBox1.Image Is My.Resources.newyork And name = "newyork" Then MsgBox("Dit antwoord is goed voor 1 punt")
If PictureBox1.Image Is My.Resources.parijs And name = "parijs" Then MsgBox("Dit antwoord is goed voor 1 punt")
If PictureBox1.Image Is My.Resources.rome And name = "rome" Then MsgBox("Dit antwoord is goed voor 1 punt")
If PictureBox1.Image Is My.Resources.sanfransisco And name = "san fransisco" Then MsgBox("Dit antwoord is goed voor 1 punt")
If PictureBox1.Image Is My.Resources.tokio And name = "tokio" Then MsgBox("Dit antwoord is goed voor 1 punt")
If PictureBox1.Image Is My.Resources.shanghai And name = "shanghai" Then MsgBox("Dit antwoord is goed voor 1 punt")
If name = "" Then MsgBox("U heeft nog niks ingevuld, vul de juiste stad in a.u.b.")
End Sub
问题是程序不知道图片框中的图片是什么,所以我怎么知道图片框中的图片是什么?
答案 0 :(得分:0)
请尝试以下操作。请在Button1_Click
。
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim stad As Integer
Randomize()
stad = Int(Rnd() * 10) + 1
If stad = 1 Then
PictureBox1.Image = My.Resources.amsterdam
PictureBox1.Tag = "amsterdam"
ElseIf stad = 2 Then
PictureBox1.Image = My.Resources.berlijn
PictureBox1.Tag = "berlijn"
End If
End Sub
Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
Dim name As String
name = TextBox1.Text
If name = "" Then
MsgBox("U heeft nog niks ingevuld, vul de juiste stad in a.u.b.")
ElseIf TextBox1.Text.Trim = PictureBox1.Tag Then
MsgBox("Dit antwoord is goed voor 1 punt")
End If
End Sub