2

我有这个代码,它有一个错误if carloc = (250,524)。代码是检查汽车(图片框)是否在某个地方,然后在您按下“A”时将 ti 移动到其他地方。这是代码:

Public Class Form1
Dim carloc As Point
Private Sub Form1_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
     Select e.KeyCode
        Case Keys.A
            If carloc = (250,524) then
                carloc = New Point(285, 524)
                car.Location = carloc
            End If

    End Select
End Sub

结束类

4

1 回答 1

2

You would need to check the coordinates individually:

If carloc.X = 250 AndAlso carloc.Y = 524 Then
    carloc = New Point(285, 524)
    ' ....

If you're dealing with a value type (Structure), which you are in this case, or if the type implements IEquatable(Of T), you can also write:

If carloc = New Point(250, 524) Then
    carloc = New Point(285, 524)
    ' ....

This will work in this case, but not as a general rule for any type.

于 2013-04-16T00:22:34.323 回答