2017-01-16 114 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));