如何在点击时找到存储在2D数组中的Picturebox的坐标

时间:2018-06-16 13:11:56

标签: vb.net

我有一个存储在2D数组中的图片网格,我需要在点击时检索每个图片框的数组中的坐标。

图片框的存储方式如下:

    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

1 个答案:

答案 0 :(得分:0)

什么时候点击?

您可以使用此位置获取位置:

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

编辑:

 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: