2016-06-17 25 views
-1

我想創建一個二維數組相當大的二維數組,這樣我就可以每次我點擊mouse..each行將代表光標位置添加新行..建立再C#

X1 Y1 x2 y2 x3 y3 。 。 。 。 。 。

i=0 
    private void Form1_MouseDown(object sender, MouseEventArgs e) 
    { 
     i++; 
     x[i]=e.X; 
     Y[i]=e.Y; 
    //if the array not exist create one 
     int[,] numbers = new int[i, 2]{{X[i], Y[i]}}; 
     //if the array exist add row to the exist array 
     //add the row {{X[i], Y[i]} to the array 
    } 
+4

陣列是固定的大小。改用DataTable。 –

+0

你應該真的使用一個結構或一個類,而不是'struct Pos {public int X; public int Y; }'。另外,使用列表來存儲它們。陣列是固定的大小不像列表 –

回答

3

你需要的是一個System.Drawing.Point列表。點具有X和Y二者

private List<Point> points = new List<Point>(); 

private void Form1_MouseDown(object sender, MouseEventArgs e) 
{ 
    points.Add(e.Location); 
} 
+0

是啊沒有重新發明車輪 –