I have a pictureBox1_MouseDown event and when i click the mouse left button it dosent work good
<p>The idea is that in my program i have a button. When i click the button its drawing in the picutreBox1 paint event the point and add it on the pictureBox1 center + 10 pixels randomly around the center.</p>

<p>For example i clicked 5 times in a row and i see now 5 points.
In the button1 click event i also add the button location X,Y to two Lists&lt;>
List&lt;> X have the X location of the button and Y the Y location.</p>

<p>Now in the mouse down event im calculating the nearest point to the mouse location when i click the pictureBox1 and i also check if the lowest value distance is lower then 50 so if i click on a point ill be able to drag the point around the pictureBox1 but only if i clicked on the point somewhere between the point center and 5 pixels from the center.
That way i know wich point i want to drag.</p>

<p>In the mouse down event i also get the index of the lowest value distance and i set a flag movePoint to true and then in the mouse move event i update all the time the selectedIndex so only the selected clicked point will move. in the mouse mkove event i also check if the flag movePoint is true and then only start the movement.</p>

<p>In the mouse up i update once again the selectedIndex with the mouse location.
And i also set the flag movePoint to false.</p>

<p>The problem is when im running the program add one or more points but i dont click with the mouse on a point i click on EMPTY SPACE somewhere in the pictureBox1 and just click on it once or click and try to drag this empty space nothing happens since the flag movePoint is false. </p>

<p>** But in fact for some reason something does happen and if i click and drag empty space in the pictureBox1 area and then i click on one of the points and try to drag them the point jump to the location of where i dragged the empty space before !
I cant figure out why it happen. **</p>

<p>Its like i drag nothing its empty space i also dont see any point move. But then when i try to drag a point its jumping or another point is jumping to the location of where i ended dragging the empty space !!!!</p>

<p>This is the code of the mouse down mouse move mouse up and the paint events:</p>

<pre><code>private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
        {

            if (e.Button == MouseButtons.Left)
            {
                // find the index that is closest to the current mouse location
                float MinDist = float.MaxValue;

                for (int idx = 0; idx &lt; Point_X.Count; ++idx)
                {
                    float dx = Point_X[idx] - e.X;
                    float dy = Point_Y[idx] - e.Y;
                    float dist = (float)Math.Sqrt(dx * dx + dy * dy);
                    if (dist &lt; MinDist)
                    {
                        MinDist = dist;
                        selectedIndex = idx;
                    }
                }



                if (MinDist &lt; 5)
                {
                    mouseMove = true;
                    OriginalX = Point_X[(int)selectedIndex];
                    OriginalY = Point_Y[(int)selectedIndex];
                }
            }
        }

        private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
        {
            if (mouseMove == true)
            {
                Point NewPoint = e.Location;
                Point_X[(int)selectedIndex] = NewPoint.X;
                Point_Y[(int)selectedIndex] = NewPoint.Y;
                pictureBox1.Refresh();
            }

        }

        private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
        {
            Point NewPoint =  e.Location;
            Point_X[(int)selectedIndex] = NewPoint.X;
            Point_Y[(int)selectedIndex] = NewPoint.Y;
            mouseMove = false;

        }

private void pictureBox1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
        {
           Graphics g = e.Graphics;
           g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
           SolidBrush brush = new SolidBrush(Color.Red);
               for (int idx = 0; idx &lt; Point_X.Count; ++idx)
               {
                   Point dPoint = new Point((int)Point_X[idx], (int)Point_Y[idx]);
                   dPoint.X = dPoint.X - 5; // was - 2
                   dPoint.Y = dPoint.Y - 5; // was - 2
                   Rectangle rect = new Rectangle(dPoint, new Size(10, 10));
                   g.FillEllipse(brush, rect);
               }
        }  
</code></pre>

<p>Thanks for the helping.</p>

<p>** I made a small video yesterday that show the problem. look from the beginning but the problem start at second 17-19 thats where i click and drag empty space in the pictureBox1 and then try to drag the points again and cant move them and if i cant move one of them the other points jump to the location of the empty space i dragged.</p>

<p><a href="http://www.youtube.com/watch?v=qZr6wdF8MNA&amp;feature=youtu.be" rel="nofollow">http://www.youtube.com/watch?v=qZr6wdF8MNA&amp;feature=youtu.be</a> **</p>
