2012-05-13 7 views
-1

整数配列で、マウスの各クリックを格納する方法 私はそれは私が保管しなければならない機能(空ポリゴン) だ書いたので、私はポリゴンを描きたかった今の線を描くことができます配列内の各クリックの座標と、その後、私の機能は彼らに を取得する必要があり、私は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

を描画するためであるあなたは、ポイントを作ることができますクリック座標の:

Point p = new Point(e.x, e.y); 
個の

保存のポイントを一覧で取得する:あなたが通常あるでしょうどのように多くのクリック任意のアイデアを持っていないので、

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

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

配列は、良いアイデアではありません。 Listは可変長なので、このような状況では便利です。

+0

多角形の別のアルゴリズムを楽しみにしています – Nickool

+0

あなたは何をしたいのか分かりません。詳しい情報が必要な場合は別の質問をしてください。答えがあれば私の答えを記入してください。 – Hidde

関連する問題