2012-05-13 16 views
-1

我有一個bresenham算法,我在課上寫了這行 我可以畫線現在我想繪製多邊形,所以我寫了它的功能(void Polygon) 我應該存儲陣列中的每一次點擊的座標,然後我的功能應該讓他們 我不知道如何來存儲每個點擊
Radiobutton1是平局線和radiobutton2是繪製多邊形如何在整數數組中存儲鼠標的每次點擊

private void panel1_MouseClick(object sender, MouseEventArgs e) 
     {   
      if(radioButton1.Checked) 
      if (firstClick) 
      { 
       firstX = e.X; 
       firstY = e.Y; 
       firstClick = false; 
      } 
      else 
      { 
       Line l = new Line(firstX, firstY, e.X, e.Y, panel1.CreateGraphics(), Convert.ToInt32(textBox1.Text)); 

       firstClick = true; 

      } 
      if(radioButton2.Checked) 
      { 
     //how to write here so as to store each click in array 

       } 
      } 

     private void button1_Click(object sender, EventArgs e) 
     { 
      int n = Convert.ToInt32(textBox2.Text); 

      Polygon(n, coor); 
     } 
    void Polygon(int n,int[] coordinates) 
    { 
     if(n>=2) 
     { 
     Line l=new Line(coordinates[0],coordinates[1],coordinates[2],coordinates[3],panel1.CreateGraphics(), Convert.ToInt32(textBox1.Text)); 
     for(int count=1;count<(n-1);count++) 
      l=new Line(coordinates[(count*2)],coordinates[((count*2)+1)],coordinates[((count+1)*2)],coordinates[(((count+1)*2)+1)],panel1.CreateGraphics(), Convert.ToInt32(textBox1.Text)); 
     } 

回答

1

你可以提出一個觀點的點擊座標:

你在一個列表得到

保存點:

// Declaration: 
List<Point> myPoints = new List<Point>(); 

// in the method: 
if (radioButton2.Checked) { 
    myPoints.Add(new Point(e.x, e.y)); 
} 

數組將不會是一個好主意,因爲你通常沒有任何想法多少點擊就會出現。列表的長度是可變的,所以它在這種情況下很有用。

+0

然後我應該期待多邊形的另一種算法 – Nickool

+0

我不知道你想要做什麼,請問另一個問題,如果你需要更多的信息。如果是,請將我的答案標記爲答案。 – Hidde

相關問題