Vb.net 如何在单击时找到存储在二维数组中的Picturebox的坐标

Vb.net 如何在单击时找到存储在二维数组中的Picturebox的坐标,vb.net,Vb.net,我有一个存储在2D数组中的picturebox网格,我需要在单击时检索每个picturebox数组中的坐标 PictureBox的存储方式如下: Grid(1, 1) = PictureBox1 Grid(2, 2) = PictureBox2 Grid(2, 4) = PictureBox3 Grid(3, 1) = PictureBox4 Grid(4, 2) = PictureBox5 Grid(5, 1) = PictureBox6

我有一个存储在2D数组中的picturebox网格,我需要在单击时检索每个picturebox数组中的坐标

PictureBox的存储方式如下:

    Grid(1, 1) = PictureBox1
    Grid(2, 2) = PictureBox2
    Grid(2, 4) = PictureBox3
    Grid(3, 1) = PictureBox4
    Grid(4, 2) = PictureBox5
    Grid(5, 1) = PictureBox6
    Grid(7, 1) = PictureBox7
    Grid(6, 2) = PictureBox8
    Grid(9, 1) = PictureBox9
    Grid(10, 2) = PictureBox10
什么时候点击

您可以通过以下示例获取位置:

Dim test = Grid(1, 1).Location 'picturebox1.location
Dim test2 = "x location is: " & test.X & ", y location is: " & test.Y
或者直接与

Dim test3 = Grid(1, 1).Location.x 'or y
编辑:


到目前为止,您尝试了什么来达到您想要的结果?我不知道从哪里开始,我尝试将x和y声明为变量,但是我不知道如何将x和y存储在这些变量中。当单击picturebox本身时,我希望它返回该picturebox在2d阵列中的位置,例如(1,1)是的,没错。这就是我想说的。好吧,有多种方法,最好的解决方案取决于你的需要。我只需在它上面循环找到我需要的东西,两行就完成了。我将它用作游戏板,所以我需要能够将它与数组中存储的其他值进行比较,以查看移动是否合法
 For y = 0 To Grid.GetLength(0)-1 'row count
        For x = 0 To Grid.GetLength(1)-1 'column count
            If Grid(y, x) IsNot Nothing Then
                If Grid(y, x).name = sender.name Then
                    Dim test = String.Format("y is: {0}, x is: {1}", y, x)
                    GoTo exit_for
                End If
            End If
        Next
    Next
exit_for: