2017-01-16 169 views
-1

我不知道我是否正在討論這項權利。我需要的是用戶創建所有行後,可能是1可能是10.我可以計算這些行的長度,將該行出現的區域添加到列表中。從多個列表創建列表?

所以,你到底有沒有例如

Length Location 
2  1 
4  2 
3  1 
8  1 

之後我將在Oracle服務器上添加此數據各自列。列表是否合適?我目前在Zone1和distfinal上出現了出界錯誤。如果我只是做一條線然後我得到的長度計算的,但一出界誤差對1區

List<string> Zone1 = new List<string>(); 

     private Point p1, p2; 
     List<Point> p1List = new List<Point>(); 
     List<Point> p2List = new List<Point>(); 

Dictionary<string, int> Void = new Dictionary<string, int>(); 
    private void pictureBox1_MouseDown(object sender, MouseEventArgs e) 
     { 
      if (e.Button.Equals(MouseButtons.Left)) 
      { 
       if (p1.X == 0) 
       { 
        p1.X = e.X; 
        p1.Y = e.Y; 

        var color = zoneMap1.GetPixel(e.X, e.Y); 
        if (color == Color.FromArgb(0, 0, 255)) 
        { 
         //MessageBox.Show("Zone 1"); 
         Zone1.Add("1"); 
        } 
        else if (color == Color.FromArgb(0, 255, 0)) 
        { 
         //MessageBox.Show("Zone 2"); 
         Zone1.Add("2"); 
        } 
       } 
       else 
       { 
        p2.X = e.X; 
        p2.Y = e.Y; 

        p1List.Add(p1); 
        p2List.Add(p2);  

        Invalidate(); 
        pictureBox1.Refresh(); 
        p1.X = 0; 
       } 
      } 
     } 


     private void pictureBox1_Paint(object sender, PaintEventArgs e) 
     { 
      using (var p = new Pen(Color.Red, 5)) 
      { 
       for (int x = 0; x < p1List.Count; x++) 
       { 
        e.Graphics.DrawLine(p, p1List[x], p2List[x]); 
       } 
      } 
     } 

與我有什麼在這裏,假設我正確會對此,有Void.Add(Zone1[i], distfinal);

發生的錯誤最終,我想創建所有的線。然後使用下面的按鈕創建我在頂部給出的示例。

private void btnCalc_Click(object sender, EventArgs e) 
{ 
    for (int i = 0; i < p1List.Count; i++) 
    { 
     if (p1List.Count != 0 && p2List.Count != 0) 
     { 
      dist = (Convert.ToInt32(Math.Pow(p1.X - p1.Y, 2) + Math.Pow(p2.X - p2.Y, 2))); 
      int distfinal = (dist % 32); 
      Void.Add(Zone1[i], distfinal); 
     } 
     else 
     { 
      MessageBox.Show("You must first create a line"); 
     } 
    } 
} 
+2

您的錯誤發生在哪裏? – krillgar

+1

您確定'Zone1'與'p1List'具有相同數量的項目嗎? – juharr

+0

除非我的代碼錯誤。我不確定更好的方法來做到這一點。現在第一次點擊創建x並添加它創建的區域,然後第二次點擊創建y和該行。然後是第二個,依此類推。我希望首先創建該行,然後查看它創建的區域,添加它並轉到您創建的下一行,但我不知道該怎麼做。 – Lee

回答

1

嘛,學會Tuple :)

這個固定。

var list = new List<Tuple<string, int>>(); 
list.Add(new Tuple<string, int>(Zone1[i], distfinal));