2016-06-17 5 views
-1

c를 상당한 이차원 배열을 재를 만들고, 그래서 새로운 행을 I는 mouse..each 행이 커서 위치를 나타내는 것이다 클릭 할 때마다 추가.. I는 2 개 차원 배열을 생성 할 #

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

예. 휠을 다시 만들지 않아도됩니다. –

관련 문제