Beispiel #1
0
        private void Form1_MouseClick(object sender, MouseEventArgs e) //mouseclick event handler
        {
            if (e.Button == MouseButtons.Left)                         //if left button is pushed
            {
                PointValues p = new PointValues(e.X, e.Y, false);      //create and add coordinates to an array list
                this.coordinates.Add(p);
                this.Invalidate();
            }

            if (e.Button == MouseButtons.Right) //right button pushed
            {
                bool in_circle = false;
                int  total     = coordinates.Count;
                int  index     = total - 1;
                for (int i = index; i >= 0; i--)
                {
                    PointValues p = (PointValues)coordinates[i];
                    if ((Math.Abs(e.X - p.X) < 10) && (Math.Abs(e.Y - p.Y) < 10))
                    {
                        if (p.red_black == false) //if black
                        {
                            p.red_black = true;   //turned red on right click
                            in_circle   = true;   //you're in the circle
                            this.Invalidate();
                        }

                        else if (p.red_black == true) //if red
                        {
                            coordinates.RemoveAt(i);  //remove coordinates from array list on right click
                            in_circle = true;         //you're in the circle
                            this.Invalidate();
                        }
                    }
                }

                if (in_circle == false)       //if right click not in circle
                {
                    this.coordinates.Clear(); //clear coordinates
                    this.Invalidate();
                }
            }
        }
Beispiel #2
0
        private void Form1_MouseClick(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                //creates and adds coordinates to array list

                PointValues p = new PointValues(e.X, e.Y, false);
                this.coordinates.Add(p);
                this.Invalidate();
            }

            if (e.Button == MouseButtons.Right)
            {
                int total = coordinates.Count;
                int index = total - 1;
                for (int i = index; i >= 0; i--)
                {
                    PointValues p = (PointValues)coordinates[i];
                    if ((Math.Abs(e.X - p.X) < 10) && (Math.Abs(e.Y - p.Y) < 10))
                    {
                        //if circle is black
                        if (p.red_black == false)
                        {
                            p.red_black = true; //will turn red with right click

                            this.Invalidate();
                        }
                        //if red circle
                        else if (p.red_black == true)
                        {
                            coordinates.RemoveAt(i); //remove coordinates from array list via right click

                            this.Invalidate();
                        }
                    }
                }
            }
        }