How do i check which point to delete?
<p>I have two <code>List</code>s of type <code>int</code> where I store point coordinates called <code>Point_X</code> and <code>Point_Y</code>.</p>

<p>This is the delete method in the new class:</p>

<pre><code>public void DeletePoint(int x, int y)
{
    for (int i = 0; i &lt; Point_X.Count; i++)
    {
        if ((i == x) &amp;&amp; (i == y) || y == -1 || x == -1) 
        {
            Point_X.RemoveAt(i);
            Point_Y.RemoveAt(i); 
        }
        else
        {
        }
    }
}
</code></pre>

<p>In <code>x</code> and <code>y</code>, I'm getting the index of the point I clicked. If I add two points and click on one of them so I'm getting two indexes of the point, e.g. <code>x</code> will be 0 and <code>y</code> will be -1.</p>

<p>Now I'm running through the <code>Point_X</code> list and I need to check for all situations and compare the indexes I'm getting with the indexes in the lists <code>Point_X</code> and <code>Point_Y</code> and then it should remove the point I clicked on.</p>

<p>This <code>if</code> doesn't seem to be working: <code>if ((i == x) &amp;&amp; (i == y) || y == -1 || x == -1)</code>. 
If I have two points in <code>pictureBox1</code> and I click on point number 2 and try to delete it, it doesn't get removed the first time around. It does get removed the second time I click though.</p>

<p>This is the code of the button click in <code>Form1</code> where I click to delete the point:</p>

<pre><code>private void button3_Click(object sender, EventArgs e)
{           
    wireObject1.DeletePoint(cyclicSelectedIndex[0],cyclicSelectedIndex[1]);
    button3.Enabled = false;
}
</code></pre>

<p>This is the code where I click on the point I want to select in <code>pictureBox1</code>'s <code>MouseDown</code> event:</p>

<pre><code>private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
    if (e.Button == MouseButtons.Left)
    {
        label1.Visible = true;
        label4.Visible = true;

        // find the index that is closest to the current mouse location
        float t = wireObject1.GetIndexByXY(e.X, e.Y, 5);

        if (t == -1)
        {
            button3.Enabled = false;
        }
        else
        {
            button3.Enabled = true;
            {
                selectedIndex = t;
                mouseMove = true;
                OriginalX = wireObject1._point_X[(int)selectedIndex];
                OriginalY = wireObject1._point_Y[(int)selectedIndex];

                if (cyclicSelectedIndex.Count() == 2)
                {
                    cyclicSelectedIndex[currentCyclicIndex] = (int)selectedIndex;
                    currentCyclicIndex++;
                    if (currentCyclicIndex == 2)
                    {
                        currentCyclicIndex = 0;
                    }

                    if ((cyclicSelectedIndex[0] == cyclicSelectedIndex[1]) || (cyclicSelectedIndex[0] == -1) || (cyclicSelectedIndex[1] == -1))
                    {
                        button2.Enabled = false;
                    }
                    else
                    {
                        button2.Enabled = true;
                    }

                    for (int i = 0; i &lt; wireObject1._connectionstart.Count; i++) 
                    {
                        if ((wireObject1._connectionstart[i] == cyclicSelectedIndex[0] &amp;&amp; wireObject1._connectionend[i] == cyclicSelectedIndex[1]) ||
                                   (wireObject1._connectionstart[i] == cyclicSelectedIndex[1] &amp;&amp; wireObject1._connectionend[i] == cyclicSelectedIndex[0]))
                        {
                             button2.Enabled = false;
                        }
                    }

                    label13.Text = selectedIndex.ToString();
                    label13.Visible = true;
                    label14.Visible = true;

                    listView1.Items.Add(selectedIndex.ToString()).EnsureVisible();
                }
            }
        }
    }
}
</code></pre>

<p>The problem is that the <code>DeletePoint</code> method in the new class doesn't delete the point I clicked on unless I click on it twice.</p>

<hr>

<p>And it's logical <code>if ((i == x) &amp;&amp; (i == y))</code> since in some cases <code>x</code> is 1 and <code>y</code> is 0 so the variable (<code>i</code>) will never be also 0 and also 1 so I'm stuck here.</p>

<p>I don't how to check for all situations - e.g. <code>x</code> is 1 and <code>y</code> is 0. There may be other scenarios to cover but I think the problem is somewhere in this <code>if</code> statement.</p>

<hr>

<p>x = 1 , y = 1</p>

<p>Point_X >>> [0] = 331.0 , [1] = 212.0</p>

<p>Point_Y >>> [0] = 213.0 , [1] = 212.0</p>

<p>i = 0</p>

<p>This is the case when i have two points and i clicked on the second point.
It didnt do anything in the function in the new class it didnt remove the point.</p>

<p>Same for the first point it didnt remove it it didnt enter to the remove area.
This is when im using Alexei Levenkov idea sample for the If checking.</p>

<p>Now in Form1 when im clicking on a point in the pictureBox1 so in the mouse down event i have a variable(t) wich i calculate the index of the point in the new class:</p>

<pre><code>public float GetIndexByXY( int x , int y , float tol)
        {
            for (idx = 0; idx &lt; Point_X.Count; ++idx)
            {
                float dx = Point_X[idx] - x;
                float dy = Point_Y[idx] - y;
                float dist = (float)Math.Sqrt(dx * dx + dy * dy);

                if (dist &lt; tol) return idx;

            }
            return -1;
        }
</code></pre>

<p>For example if i have one point and i click on it then variable(t) = 0</p>

<p>Then the List cyclicSelectedIndex have two cells/places in [0] i have 0 and in [1] i have -1 and currentCyclicIndex is now 1 and selectedIndex is 0 thats in Form1 in mouse down event. The mouse down event is just to mark wich point i want to delete.</p>

<p>In Form1 button click where i click to the delete the point:</p>

<pre><code>private void button3_Click(object sender, EventArgs e)
        {



            wireObject1.DeletePoint(cyclicSelectedIndex[0],cyclicSelectedIndex[1]);
            button3.Enabled = false;

            pictureBox1.Invalidate();
        } 
</code></pre>

<p>cyclicSelectedIndex[0] = 0 and cyclicSelectedIndex[1] = -1</p>

<p>So in the new class in the DeletePoint function:</p>

<pre><code>public void DeletePoint(int x, int y)
        {

            for (int i = 0; i &lt; Point_X.Count; i++)
            {

                if ((Point_X[i] == x) &amp;&amp; (Point_Y[i] == y) || y == -1 || x == -1) 
                {
                    Point_X.RemoveAt(i);
                    Point_Y.RemoveAt(i); 
                }
                else
                {
                }
            }



        }
</code></pre>

<p>x = 0 and y = -1</p>

<p>Now i need to remove the index 0 and -1 from the Lists: Point_x and Point_Y and each index in this Lists contain a coordinate of hte point i want to delete.</p>
